I have a R markdown document (test.Rmd):
---
title: "R Notebook"
output: html_document
---
```{r}
require(pacman)
p_load(magrittr,rmarkdown,tidyverse)
test_tbl = tibble(a=seq(1,10),b=seq(1,10),c=seq(1,10),d=seq(1,10))
test_tbl %<>% dplyr::select(any_of(c("a","b","c")))
test_tbl
I have a R script file (test_rendering.R):
require(rmarkdown)
render(input="test.Rmd")
I can run "test.Rmd" inside Rstudio without error.
I can run "test_rendering.R" inside Rstudio without error (the rendering output for test.Rmd is created as expected).
When I run this command from the command line,
Rscript test_rendering.R
it throws an error:
Loading required package: rmarkdown
processing file: test.Rmd
|................................... | 50%
ordinary text without R code
|......................................................................| 100%
label: unnamed-chunk-1
Quitting from lines 7-12 (test.Rmd)
Error in any_of(c("a", "b", "c")) : could not find function "any_of"
Calls: render ... <Anonymous> -> vars_select_eval -> map_if -> map -> .f
Execution halted
Why is test_rendering.R throwing these errors only when it is being run from the command line?
sessionInfo():
R version 3.6.1 (2019-07-05)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.3 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] forcats_0.4.0 stringr_1.4.0 dplyr_0.8.4 purrr_0.3.3 readr_1.3.1 tidyr_1.0.2 tibble_2.1.3 ggplot2_3.2.1 tidyverse_1.3.0 magrittr_1.5 pacman_0.5.1
[12] rmarkdown_2.1
loaded via a namespace (and not attached):
[1] tidyselect_1.0.0 xfun_0.12 haven_2.2.0 lattice_0.20-38 colorspace_1.4-1 vctrs_0.2.2 generics_0.0.2 htmltools_0.4.0 yaml_2.2.1 utf8_1.1.4
[11] rlang_0.4.4 pillar_1.4.3 withr_2.1.2 glue_1.3.1 DBI_1.1.0 dbplyr_1.4.2 modelr_0.1.5 readxl_1.3.1 lifecycle_0.1.0 munsell_0.5.0
[21] gtable_0.3.0 cellranger_1.1.0 rvest_0.3.5 evaluate_0.14 knitr_1.27 fansi_0.4.1 broom_0.5.4 Rcpp_1.0.3 backports_1.1.5 scales_1.1.0
[31] jsonlite_1.6.1 fs_1.3.1 hms_0.5.3 packrat_0.5.0 digest_0.6.23 stringi_1.4.5 grid_3.6.1 cli_2.0.1 tools_3.6.1 lazyeval_0.2.2
[41] crayon_1.3.4 pkgconfig_2.0.3 ellipsis_0.3.0 xml2_1.2.2 reprex_0.3.0 lubridate_1.7.4 assertthat_0.2.1 httr_1.4.1 rstudioapi_0.10 R6_2.4.1
[51] nlme_3.1-143 compiler_3.6.1
Rstudio version: Rstudio Server Open-Source 1.2.5033