Skip to content

Operator %>% not available although imported #723

@grst

Description

@grst

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions