Consider the behavior of the following
r$> df = tibble(y = runif(100))
r$> foo = function(x, y){
x + y
}
r$> x = 1
r$> mutate(df, z = foo(x, y))
# A tibble: 100 x 2
y z
<dbl> <dbl>
1 0.485 1.48
2 0.525 1.53
3 0.296 1.30
4 0.0219 1.02
5 0.886 1.89
6 0.100 1.10
7 0.477 1.48
8 0.156 1.16
9 0.953 1.95
10 0.450 1.45
# … with 90 more rows
Clearly R is using the value x
and adding it to each entry in the vector df$y
. This is expected behavior. However I'm getting conflicting behavior with a different function.
r$> m
# A tibble: 8,635 x 1
home_mesh5
<dbl>
1 5640567434
2 5640559814
3 5640650921
4 5640661642
5 5640661642
6 5640662031
7 5640663631
8 5640663643
9 5640664611
10 5640664224
# … with 8,625 more rows
r$> mutate(m, z = mesh_to_loc(home_mesh5, LOCATION))
# A tibble: 8,635 x 2
home_mesh5 z
<dbl> <int>
1 5640567434 56405664
2 5640559814 56405664
3 5640650921 56405664
4 5640661642 56405664
5 5640661642 56405664
6 5640662031 56405664
7 5640663631 56405664
8 5640663643 56405664
9 5640664611 56405664
10 5640664224 56405664
Here LOCATION = "2 km"
.
This feels like the exact same scenario as before, but as you can see it's not broadcasting the function along every element. It's only using the first entry. What's going on here?
Proof that it's not the function that's the problem
r$> mesh_to_loc(m$home_mesh5[4], LOCATION)
[1] 56406606