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

Converting sf to sp in rmarkdown #478

Closed
jsta opened this issue Sep 5, 2017 · 2 comments
Closed

Converting sf to sp in rmarkdown #478

jsta opened this issue Sep 5, 2017 · 2 comments

Comments

@jsta
Copy link
Contributor

jsta commented Sep 5, 2017

I have two documents.

  • An Rmd file with the following:
library(sf)
x = st_sfc(st_point(c(5,5)), st_point(c(6,9)), crs = 4326)
as(x, "Spatial")
  • A build script with the following:
knitr::knit("test.Rmd", "test.md")

I am able to render the rmarkdown if I run knitr interactively. However, I if run the build script with Rscript I get an error:

## Error in as(x, "Spatial"): could not find function "as".

It does not seem to matter whether I set the envir argument to new.env() or globalenv().

@edzer
Copy link
Member

edzer commented Sep 5, 2017

It is well known that Rscript does not load methods, where R does. Start your script with an explicit library(methods) if you want it to work like it does in R.

@jsta
Copy link
Contributor Author

jsta commented Sep 5, 2017

Gah, thanks!

@jsta jsta closed this as completed Sep 5, 2017
ostueker pushed a commit to acenet-arc/ACENET_Summer_School_MPI that referenced this issue May 18, 2018
Building `md` from `Rmd` in a script like this will break if the `methods` package is not called and the code includes class object routines. See r-spatial/sf#478
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