Passing a function to an R6 field causes a `could not find function "x"` error

I've a function foo in file x.R storing an object to be passed to the field of an R6 class in file y.R. I'd like the field to store the object returned by foo() as default. I'd normally do that as follows:

# in file x.R
foo <- function(x = "blah", y = TRUE) {
  # do stuff
}

# in file y.R
Bar <- R6::R6Class(
  "Bar",
  public = list(
    field = foo(),
    # ...
  )
)

I'm getting a could not find function "foo" error when installing the package though. How could a do this without getting an error?

Declaring the function in the same file, right before the class isn't an option. Defining the value of the field within initialize() doesn't work for me either.

Edit:
Just adding that function foo is properly exported.

This topic was automatically closed after 45 days. New replies are no longer allowed.


If you have a query related to it or one of the replies, start a new topic and refer back with a link.