[R-pkg-devel] Issue with closures & devtools::document/check

Winston Chang winstonchang1 at gmail.com
Sun Jun 28 21:58:33 CEST 2015


This is a devtools-specific question, so it really belongs on the
rdevtools mailing list:
  https://groups.google.com/forum/#!forum/rdevtools


That said, this is probably happening because square.R is being
processed before testClosure.R. By default, the files are processed in
lexicographical order.

If you want to change that, you can add this to the top of square.R:

#' @include testClosure.R


-Winston

On Sun, Jun 28, 2015 at 2:13 PM, James Toll <james at jtoll.com> wrote:
> Hi,
>
> I’m working on putting together a package of some functions I’ve been using and I’m running into an issue with closures.  I’m using Rstudio and devtools.  Here is a simple example that shows the problem I’m having.
>
> file: R/testClosure.R
> #' Test Closure
> #'
> #' This function is an example of a closure.
> #'
> #' @param y a number.
> #'
> #' @return A function.
> #' @export
> testClosure <- function (y) {
>     function (x) {
>         x ^ y
>     }
> }
>
> file: R/square.R
> #’ Square a number
> #'
> #' This function squares a number.
> #'
> #' @param x a number.
> #'
> #' @return A number.
> #' @export
> sq <- testClosure(2)
>
>
> If I try to run document() or check() from devtools, I get these errors.
>> document()
> Updating pda documentation
> Loading pda
> Error in eval(expr, envir, enclos) (from square.R#9) :
>   could not find function "testClosure"
>> check()
> Updating pda documentation
> Loading pda
> Error in eval(expr, envir, enclos) (from square.R#9) :
>   could not find function “testClosure"
>
> If I create something similar, that’s not a closure, I don’t have any path issues finding the other function.  This seems to only happen when I try to use a closure.  Any thoughts or suggestions on what might be happening here?  Thank you.
>
> James
>
> ______________________________________________
> R-package-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel



More information about the R-package-devel mailing list