4

I am running an R CMD check using devtools::check() for a package I am writing and I encountered the following NOTE in the check:

* checking R code for possible problems ... NOTE prep: no visible global function definition for 'one_of'

The only place in which I use one_of in prep() is with this line:

raw_data <- dplyr::select(raw_data, -one_of(drop_vars))

Does anyone knows how can I solve this NOTE?

Bellow is my DESCRIPTION and NAMESPACE files.

Any help would be greatly appreciated

Here is how my DESCRIPTION file looks like:

Package: prepdat
Title: xxx
Version: 0.0.0.9000
Authors@R: person("Ayala S.", "Allon", email = "ayalaallon@gmail.com", role = c("aut", "cre"))
Description:xxx
Depends: R (>= 3.0.3)
License: GPL-3
LazyData: true
Imports: dplyr (>= 0.4.2),
    reshape2 (>= 1.4.1),
    psych(>= 1.5.4)
Suggests: knitr,
    testthat

And here is how my NAMESPACE file looks like

importFrom(dplyr,"%>%")
importFrom(psych,"harmonic.mean")
exportPattern("^[^\\.]")
DavidPostill
  • 7,734
  • 9
  • 41
  • 60
ayalaall
  • 145
  • 2
  • 16
  • Have you add the `@import dplyr` tag above your function? I think this is where the `one_of` function is defined. If you use the `@import` statement, there is no need for defining `dplyr::` in front of select. – drmariod Aug 18 '15 at 11:26
  • @drmariod Thank you for your comment. Can you please clarify what you mean? The line of code in which I use `-one_of` is one line inside a bigger function. Should I add a line of `@import dplyr` before my big function? Thanks! Ayala – ayalaall Aug 18 '15 at 11:38
  • Perhaps try to also import package `lazyeval` and then use `select_(iris, interp(~-one_of(x), x = drop_vars))` – talat Aug 19 '15 at 09:04

1 Answers1

3

one_of is not an exported function from dplyr so you can not use it in your package.

As stated in the this vignette (which I advise you to read), it is better to program with dplyr using the underscored variants like select_.

Try this

raw_data <- dplyr::select_(raw_data, "-one_of(drop_vars)")

Also, I would avoid using the pipe operator within a package code. It is aimed at interactive use rather than for use within a function.

Martin Mächler
  • 4,619
  • 27
  • 27
  • Thank you. I decided not to use `dplyr::one_of` in my code. This is what I did: `drop_vars` is still a string vector argument (e.g., `drop_vars = c("prime_type", "font_size")` with the name of the columns you want to drop. Inside the function: `index_col <- c() # Reset i to 1 i <- 1 while (i <= length(drop_vars)) { index_col[i] <- which(colnames(raw_data) == drop_vars[i]) i <- i + 1} keep_col <- -index_col raw_data <- raw_data[, keep_col]`. It works great. The idea to use which I got from answer #2 in http://stackoverflow.com/questions/4427234/get-column-index-from-label-in-a-data-frame – ayalaall Aug 19 '15 at 10:09