I tried to do this in another function:
#' @import dplyr
#' @importFrom unitted mutate_.unitted_data.frame
...
x <- function() {
...
y <- u(data.frame(i=1:4, j="k"), c("ii","jj"))
site_names <- c("A","B","C")
y < - mutate(y, h=site_names)
...
}
but that didn't work because the version of mutate that got called was all dplyr, no unitted.
Warning messages:
1: In class(x) <- c("tbl_df", "tbl", "data.frame") :
Setting class(x) to multiple strings ("tbl_df", "tbl", ...); result will no longer be an S4 object
So then I tried to specify the unitted version
#' @import dplyr
#' @importFrom unitted mutate_.unitted_data.frame
...
x <- function() {
...
y <- u(data.frame(i=1:4, j="k"), c("ii","jj"))
site_names <- c("A","B","C")
y < - mutate_.unitted_data.frame(y, h=site_names)
...
}
but the problem here is that site_names is a local variable, and it doesn't get properly evaluated in mutate_.
Error in unitted(object, units, ...) :
error in evaluating the argument 'object' in selecting a method for function 'unitted': Error in unitted(object, units, ...) : binding not found: 'A'
Similarly, if you change the mutate line to this:
y < - mutate_.unitted_data.frame(y, h="site_names")
you get this:
Error in unitted(object, units, ...) :
error in evaluating the argument 'object' in selecting a method for function 'unitted': Error in unitted(object, units, ...) : binding not found: 'site_names'
We need mutate() without the _, and we need to be able to specify that we want the unitted version.
I tried to do this in another function:
but that didn't work because the version of mutate that got called was all dplyr, no unitted.
So then I tried to specify the unitted version
but the problem here is that site_names is a local variable, and it doesn't get properly evaluated in mutate_.
Similarly, if you change the mutate line to this:
you get this:
We need mutate() without the _, and we need to be able to specify that we want the unitted version.