Skip to content

using dplyr-unitted functions within other packages #19

@aappling-usgs

Description

@aappling-usgs

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions