Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Operator %>% not available although imported #723

Closed
grst opened this issue Mar 22, 2018 · 1 comment
Closed

Operator %>% not available although imported #723

grst opened this issue Mar 22, 2018 · 1 comment

Comments

@grst
Copy link

grst commented Mar 22, 2018

I have a minimal R package

R/test.R
DESCRIPTION

with test.R:

#' @import dplyr
NULL

#' A simple exported object
#'
#' @export
my_object = c(2.0, 4.0) %>% mean()

and Imports: dplyr in my DESCRIPTION.

When I run

Rscript -e "library(devtools); document()"

I get the following error message:

Updating testpkg documentation
Loading testpkg
Error in c(2, 4) %>% mean() (from test.R#7) : could not find function "%>%"
Calls: document ... withr_with_dir -> force -> source_many -> source_one -> eval -> eval
Execution halted

Is that expected behaviour?

My understanding was that roxygen2 should write all imports to the NAMESPACE file, but it already fails before the NAMESPACE file is written, because a package is not loaded.

obviously, this affects any other function that is used outside a function() in test.R and is not limited to %>%.

Note

If I use

#' A simple exported function
#'
#' @export
my_function = function() {
  c(2.0, 5.0) %>% mean()
}

instead, everything works as expected.

@hadley
Copy link
Member

hadley commented Jun 28, 2018

Should work in the development version, although importing all of dplyr is ill-advised.

@hadley hadley closed this as completed Jun 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants