R package not available in batch mode - r

I have been running a bash script (under Ubuntu) that calls and runs some R scripts to plot some maps with ggplot2. As it is a production system I don't update any new R or package releases. But recently I tried to install plotly with an error message output.
Now, when trying to run the script (calling a php webpage trhough a browser; that was running fine for a lot of time) an error with crayon package halts and exits the script without plotting the maps.
'/usr/lib/R/bin/R --slave --no-restore --no-save --no-restore --file=./RAMS-mapa-onades-zones-manual.R'
Loading required package: sp
Loading required package: methods
Checking rgeos availability: TRUE
Error : .onLoad failed in loadNamespace() for 'pillar', details:
call: loadNamespace(name)
error: there is no package called 'crayon'
Error: package or namespace load failed for 'ggplot2'
Execution halted
But if I run from a terminal or with RStudio server crayon package is loaded, ggplot2 is also properly loaded, and the maps are produced.
crayon package (located at /home/meteo/R/i686-pc-linux-gnu-library/3.1) called as
library("crayon", lib.loc= c("/home/meteo/R/i686-pc-linux-gnu-library/3.1", "/usr/local/lib/R/site-library", "/usr/lib/R/library"))
R session info on Rstudio Server:
> sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: i686-pc-linux-gnu (32-bit)
Running under: Ubuntu precise (12.04.5 LTS)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=C LC_COLLATE=C LC_MONETARY=C LC_MESSAGES=C
[7] LC_PAPER=C LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=C LC_IDENTIFICATION=C
attached base packages:
[1] grid stats graphics grDevices utils datasets methods base
other attached packages:
[1] crayon_1.3.4 rgdal_0.9-1 rgeos_0.3-8 raster_2.3-24 gpclib_1.5-5 mapproj_1.2-2 maps_2.3-9
[8] stringr_0.6.2 plyr_1.8.1 ggplot2_3.2.0 maptools_0.8-34 sp_1.2-3
loaded via a namespace (and not attached):
[1] Rcpp_1.0.1 magrittr_1.5 tidyselect_0.2.5 munsell_0.5.0 colorspace_1.2-4 lattice_0.20-33 R6_2.4.0
[8] rlang_0.3.4 dplyr_0.8.1 tools_3.2.2 gtable_0.1.2 withr_2.1.2 digest_0.6.8 lazyeval_0.2.2
[15] assertthat_0.2.1 tibble_2.1.3 purrr_0.3.2 glue_1.3.1 labeling_0.3 pillar_1.4.1 scales_1.0.0
[22] foreign_0.8-66 pkgconfig_2.0.2
Maybe there is a version conflict? How do I check?

what version of R is in /usr/lib/R/bin/R? Basically it appears you are in a slight "dependency hell" I would run /usr/lib/R/bin/R and check to see if crayon is installed there. #Alexis is correct though, it is not wise to mix versions like that. Let R handle library location unless you are trying to separate packages. Check the libraries for 3.2.2 and see if crayon is installed. you may have switched your R version since plotly depends on R >=3.2.0 https://cran.r-project.org/web/packages/plotly/
I think the easy fix would be to correct your .libpaths() i.e not call the 3.1 library and install the correct version of the packages you need.
OR
switch from R 3.2 back to R 3.1

Related

Fail to install tdplyr package. error: argument is not an environment

thanks for checking out my very first post. please bear with my formatting.
Issue summary: I have been using tdplyr to access teradata database with no issue until I tested another package called dplyr.teradata for potential performance enhancement. However I can no longer connect to the database due to the following error messages:
Error: package or namespace load failed for 'tdplyr':.onLoad failed
in loadNamespace() for 'tdplyr', details:
call: parent.env(from)
error: argument is not an environment
so I deleted the dplyr.teradata package, thought that would allow my original tdplyr to work, but I still get the same error message above. then I deleted the tdplyr package without backup, trying to reinstall using the original script below:
install.packages('tdplyr',repos=c('https://teradata-download.s3.amazonaws.com','https://cloud.r-
project.org'))
but fail to install because of the same error again. Hope someone could advise on fix.
My sessioninfo is below:
sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 16299)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] rlang_0.4.10 teradatasql_17.0.0.8 odbc_1.3.0 dplyr_1.0.2
[5] dbplyr_2.0.0 digest_0.6.27 DBI_1.1.0 hms_0.5.3
[9] bit64_4.0.5 bit_4.0.4
loaded via a namespace (and not attached):
[1] Rcpp_1.0.5 rstudioapi_0.13 magrittr_1.5 tidyselect_1.1.0 R6_2.4.1
[6] blob_1.2.1 tools_4.0.3 xfun_0.20 tinytex_0.28 ellipsis_0.3.1
[11] assertthat_0.2.1 tibble_3.0.4 lifecycle_0.2.0 crayon_1.3.4 zip_2.1.1
[16] purrr_0.3.4 vctrs_0.3.6 glue_1.4.2 openxlsx_4.2.3 stringi_1.5.3
[21] compiler_4.0.3 pillar_1.4.6 generics_0.0.2 pkgconfig_2.0.3
found the answer myself. Pasting the answer below.
The Teradata R package is incompatible with dbplyr v2.0.0 and its later versions, which introduced some breaking changes. To use tdplyr, the version of dbplyr package must be v1.4.4. tdplyr should be installed using the following commands from your Terminal (for Linux and Mac) or Command Prompt (for Windows), till a new version that is compatible with dbplyr v2.0.0 and its later versions is released:
Install dbplyr v1.4.4 first. There are various ways to install a specific version of a R package. Teradata recommends using the following command:
Rscript -e "remotes::install_version('dbplyr',version='1.4.4',repos='https://cloud.r-project.org')"
Note: To run this above command, the R package remotes should be present on the client machine.
Next to download and install tdplyr and dependencies automatically, if minimum required versions are not met, specify the Teradata R package repository and CRAN in the repos argument for install.packages.
Rscript -e "install.packages('tdplyr',repos=c('https://teradata-download.s3.amazonaws.com','https://cloud.r-project.org'))"

Error installing tidyr on Ubuntu 18.04 & R 4.0.2

In trying to install the package tidyverse, I get errors in the installation of dependency tidyr.
Here is the tail of the message I get:
cpp11.cpp:31:100: error: ‘unmove’ is not a member of ‘cpp11’
return cpp11::as_sexp(simplifyPieces(cpp11::unmove(cpp11::as_cpp<cpp11::list>(pieces)), cpp11::unmove(cpp11::as_cpp<int>(p)), cpp11::unmove(cpp11::as_cpp<bool>(fillLeft))));
^~~~~~
cpp11.cpp:31:138: error: ‘unmove’ is not a member of ‘cpp11’
return cpp11::as_sexp(simplifyPieces(cpp11::unmove(cpp11::as_cpp<cpp11::list>(pieces)), cpp11::unmove(cpp11::as_cpp<int>(p)), cpp11::unmove(cpp11::as_cpp<bool>(fillLeft))));
^~~~~~
/usr/lib/R/etc/Makeconf:176: recipe for target 'cpp11.o' failed
make: *** [cpp11.o] Error 1
ERROR: compilation failed for package ‘tidyr’
* removing ‘/home/xxx/yyy/tidyr’
Warning in install.packages :
installation of package ‘tidyr’ had non-zero exit status
To my naive eye, it would seem the issue lies with cpp11. I saw a similar question regarding tidyr installation error due to cpp11 compilation error (R tidyr package installation failed due to cpp11 compilation error (expansion pattern x contains no argument packs)), but it was for a RHEL system.
I have the latest version of gcc/c++ installed on my system (4:7.4.0-1ubuntu2.3). The latest version of system dependencies libcurl4-openssl-dev libssl-dev libxml2-dev are also installed.
Here is the output of sessionInfo():
R version 4.0.2 (2020-06-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.5 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_CA.UTF-8 LC_NUMERIC=C LC_TIME=en_CA.UTF-8 LC_COLLATE=en_CA.UTF-8 LC_MONETARY=en_CA.UTF-8 LC_MESSAGES=en_CA.UTF-8
[7] LC_PAPER=en_CA.UTF-8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] rstudioapi_0.11 magrittr_1.5 usethis_1.6.1 devtools_2.3.1 pkgload_1.1.0 R6_2.4.1 rlang_0.4.7 fansi_0.4.1 tools_4.0.2
[10] pkgbuild_1.1.0 sessioninfo_1.1.1 cli_2.0.2 withr_2.2.0 ellipsis_0.3.1 remotes_2.2.0 assertthat_0.2.1 digest_0.6.25 rprojroot_1.3-2
[19] crayon_1.3.4 processx_3.4.3 callr_3.4.3 fs_1.5.0 ps_1.3.3 curl_4.3 testthat_2.3.2 memoise_1.1.0 glue_1.4.1
[28] compiler_4.0.2 desc_1.2.0 backports_1.1.8 prettyunits_1.1.1
It looks like #hadley released an update to tidyr a few days ago, based on the new cpp11 package: https://github.com/tidyverse/tidyr/releases.
For some reason, this caused tidyr to not build for us.
Our (hopefully temporary!) workaround was like this:
(1) Remove dependency on tidyverse. Instead, explicitly depend on the subpackages( like dplyr/ggplot2/etc. )
(2) Install tidyr in the following way:
packageurl <- "https://cran.r-project.org/src/contrib/Archive/tidyr/tidyr_1.1.0.tar.gz"
install.packages(packageurl, repos=NULL, type="source")
Looks like the following commit is addressing this, though not sure when it will be pushed to CRAN: https://github.com/r-lib/cpp11/commit/779669a4d0b07e9f9d9382114f44e4f6ff68eebb
I found the following here: https://github.com/tidyverse/tidyr/issues/1024
The workaround consists in downgrading cpp11 to version 0.1:
devtools::install_version("cpp11", version = "0.1", repos = "http://cran.us.r-project.org")
Based on the answers from #djacobs7, #mkamenet3, and #Leandro R. M. de Marco, I ended up implementing the following solution, which worked for me.
Removing the cpp11 package, which I had installed from cran.
Re-installing the cpp11 package, but this time from github, as it contains the commit mentioned by #mkamenet3.
devtools::install_github("r-lib/cpp11")
Installing tidyr normally
install.packages("tidyr")

Unable to run packages from GitHub in R using devtools

Every time I try to download a package from GitHub using devtools I get an error. I'm currently trying to open the elan package:
library(devtools)
devtools::install_github("dalejbarr/elan")
I get the following error:
Installing package into ‘C:/Users/Daniel &
Catherine/Documents/R/win-library/3.6’ (as ‘lib’ is unspecified)
Error: no packages specified The system cannot find the path
specified. Error: Failed to install 'elan' from GitHub: (converted
from warning) installation of package
‘C:/rtemp/Rtmp0gabkG/file5580567f6ac9/elan_0.1.tar.gz’ had non-zero
exit status
I've tried the solutions suggested here and here, but neither fix the problem. I understand that there might be a problem with the spaces in the path name, but there's not much I can do about that (I don't want to set up a new user on my computer just to run devtools).
My SessionInfo() is:
R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)
Matrix products: default
locale:
[1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252 LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C LC_TIME=English_United Kingdom.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] devtools_2.2.2 usethis_1.5.1
loaded via a namespace (and not attached):
[1] Rcpp_1.0.2 rstudioapi_0.10 magrittr_1.5 pkgload_1.0.2 R6_2.4.0 rlang_0.4.0 tools_3.6.1 pkgbuild_1.0.3 sessioninfo_1.1.1 cli_1.1.0 withr_2.1.2 ellipsis_0.3.0
[13] remotes_2.1.1 assertthat_0.2.1 digest_0.6.21 rprojroot_1.3-2 crayon_1.3.4 processx_3.4.0 callr_3.3.0 fs_1.3.1 ps_1.3.0 curl_3.3 testthat_2.2.1 memoise_1.1.0
[25] glue_1.3.1 compiler_3.6.1 desc_1.2.0 backports_1.1.5 prettyunits_1.0.2
Looking at the source code at https://github.com/dalejbarr/elan/blob/master/DESCRIPTION I found a potential error of format. You could try to clone the repository and debug it manually by removing the extra spaces in front on the XML package import :
DESCRIPTION file
Package: elan
Title: Read ELAN XML files
Version: 0.1
Authors#R: "Dale Barr <dalejbarr3#gmail.com> [aut, cre]"
Description: Read ELAN XML files to tidy output
Depends:
R (>= 3.1.1),
dplyr
Imports:
XML,
plyr
License:
LazyData: true
RoxygenNote: 7.0.2
I tried it in a minimal package and this raise a problem (but the package still compiles without the scripts).
Alternatively you could use the XML(which this small package uses) or the xml2 (as here) package to parse your XML files.

How to run a package's testthat tests

For a given installed package, how do I run its testthat tests? I'm not a developer of the installed package, I'm a user. I just want to run its test suite to confirm its tests pass in my environment. I've tried test_check and test_package but I see errors.
To be more specific, I know its test suite fails and I want to run the tests in an interactive R session so I can debug it.
> require(eplusr) # choice of package unimportant. Any using testthat will do.
Loading required package: eplusr
> require(testthat)
Loading required package: testthat
> test_check("eplusr")
Error in test_files(paths, reporter = reporter, env = env, stop_on_failure = stop_on_failure, :
No matching test file in dir
> test_package("eplusr")
Error: No tests found for eplusr
> sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.1 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/openblas/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/libopenblasp-r0.2.20.so
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 LC_PAPER=en_US.UTF-8
[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] testthat_2.0.0 eplusr_0.9.1
loaded via a namespace (and not attached):
[1] Rcpp_0.12.18 magrittr_1.5 units_0.6-0 hms_0.4.2 progress_1.2.0 uuid_0.1-2 bit_1.1-14 debugme_1.1.0 R6_2.2.2 rlang_0.2.2
[11] stringr_1.3.1 blob_1.1.1 tools_3.5.1 data.table_1.11.5 cli_1.0.0 DBI_1.0.0 withr_2.1.2 bit64_0.9-7 assertthat_0.2.0 digest_0.6.16
[21] tibble_1.4.2 crayon_1.3.4 processx_3.2.0 readr_1.1.1 callr_3.0.0 later_0.7.4 base64enc_0.1-3 ps_1.1.0 fasttime_1.0-2 memoise_1.1.0
[31] RSQLite_2.1.1 stringi_1.2.4 pillar_1.3.0 compiler_3.5.1 prettyunits_1.0.2 lubridate_1.7.4 pkgconfig_2.0.2
R doesn't install the testthat tests by default. To do so try :
install.packages('eplusr', INSTALL_opts="--install-tests", type='source')
Then, either:
testthat::test_package('eplusr')
or alternatively using the built-in testInstalledPackage:
tools::testInstalledPackage('eplusr')
You can't (unless you reinstall overriding default behaviour as shown in Brodie's answer).
It's a design flaw^Hchoice. testthat, in all its wisdom, decided to not install tests by default by enforcing the placement in the tests/ directory. R offers an option to override it (as shown) which is generally not turned on. Hence the dilemma.
Of course, RUnit did it correctly all along having tests below inst/. So if a package uses RUnit you can run its tests once installed. Without having to reinstall it.
Edit: 1 1/2 years later, many of us now use the tinytest package which arrived within the last year. Among other advantages, also allows very easy testing of installed packages.

Cannot load package in R

Since yesterday, I cannot load some common used packages, e.g. reshape2 and stringr through library command.
Step to reproduce my problem:
1) Start a new session in Rstudio server (Version 0.99.467). I also kill the active-sessions in Rstudio server.
2) Run these codes
library(ggplot2)
library(stringr)
3) Get an error message:
Error in unloadNamespace(package) :
namespace ‘stringr’ is imported by ‘reshape2’ so cannot be unloaded
Show Traceback
Rerun with Debug
Error in library(stringr) : “stringr” version 0.6.2 cannot be unloaded.
But I don't get error if stringr is loaded before ggplot2. How should I fix this problem. Thanks for any suggestions.
I may have to update R to 3.2
My R session info:
R version 3.1.3 (2015-03-09)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu precise (12.04.5 LTS)
locale:
[1] LC_CTYPE=en_AU.UTF-8 LC_NUMERIC=C LC_TIME=en_AU.UTF-8 LC_COLLATE=en_AU.UTF-8
[5] LC_MONETARY=en_AU.UTF-8 LC_MESSAGES=en_AU.UTF-8 LC_PAPER=en_AU.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_AU.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggplot2_1.0.0
loaded via a namespace (and not attached):
[1] colorspace_1.2-4 digest_0.6.4 grid_3.1.3 gtable_0.1.2 MASS_7.3-39 munsell_0.4.2 plyr_1.8.1
[8] proto_0.3-10 Rcpp_0.11.2 reshape2_1.4 scales_0.2.4 stringr_0.6.2 tools_3.1.3
I resolved my problem through updating R and all R packages.
I guess the problem is caused by old version of stringr or reshape2 as I install the same packages in different places (system folder or personal library). R tried to load a old version of package.
Even though it is a good practice to update R for me it was not necessary to solve the same issue. The problem can result from few .libPaths(). With .libPaths("C:/Program Files/R/R-3.4.3patched/library") you can point out one folder. After that just reinstall of packages, and it should work.
My code:
> .libPaths()
[1] "L:/My Documents/R/win-library/3.4" "C:/Program Files/R/R-3.4.3patched/library"
> .libPaths("C:/Program Files/R/R-3.4.3patched/library")
> packages<-c('ggplot2','data.table','knitr','xtable')
> install.packages(packages)
> lapply(packages,library,character.only=T)
Even though the issue is solved I hope it will help someone.

Resources