GithubHelp home page GithubHelp logo

Comments (4)

gaborcsardi avatar gaborcsardi commented on June 11, 2024

This is not a callr issue. It is an S3 method lookup issue. E.g. this fails the same way:

f <- function(n) {
  point <- function(x, y) {
    stopifnot(is.numeric(x), is.numeric(y))
    structure(list(x = x, y = y), class = "point")
  }

  abs.point <- function(x) {
    sqrt(x$x ^ 2 + x$y ^ 2)
  }

  points <- mapply(point, runif(n), runif(n), SIMPLIFY = FALSE)

  sapply(points, abs)
}
f(10)
#> Error in FUN(X[[i]], ...) : non-numeric argument to mathematical function

I think it is a bug in base R, but R-core devs might not share this opinion. One workaround is to put the S3 method definition into .GlobalEnv (i.e. outside of a function in the Rmd for you).

from callr.

nbenn avatar nbenn commented on June 11, 2024

Thanks for the quick feedback.

Sorry to insist. Do you also not consider this a bug in my original scenario? There I did not have my s3 method definition wrapped in a function. My knitr code chunk is something like

point <- function(x, y) {
  stopifnot(is.numeric(x), is.numeric(y))
  structure(list(x = x, y = y), class = "point")
}

abs.point <- function(x) {
  sqrt(x$x ^ 2 + x$y ^ 2)
}

points <- mapply(point, runif(5), runif(5), SIMPLIFY = FALSE)

sapply(points, abs)

When I create my .md using rmarkdown::render, all is fine. However pkgdown wraps render with r_safe, which causes the markdown generation to fail. If you agree that something seems off, I will open an issue at pkgdown.

from callr.

gaborcsardi avatar gaborcsardi commented on June 11, 2024

rmarkdown::render evaluates code in an empty environment by default and this messes up the S3 lookup as well. You can set its envir argument to .GlobalEnv to work around this. This is done here: https://github.com/r-lib/pkgdown/blob/d4e9509f99265a551f03ef2696d2f0393f24103c/R/build-articles.R#L114-L123

But it is not done here:
https://github.com/r-lib/pkgdown/blob/c8726f9242b2b67f572c16422c83cdc8160c7628/R/build-home.R#L72-L79

So maybe the latter is biting you, and then yes, this needs a fix in pkgbuild.

from callr.

nbenn avatar nbenn commented on June 11, 2024

Thanks for getting back to me.

from callr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.