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.
Related
I have ggplot2 3.4.0 installed on Ubuntu 22.04, but for some reasons I would like to use older version ggplot2 3.3.6.
library(ggplot2, lib.loc="~/R/ggplot336/")
I worked fine when I started with a clean script file. However, when I use an existing script file like:
library(ggplot2, lib.loc="~/R/ggplot336/")
ggimage::geom_image()
I got the following error massage:
Error in value[3L] :
Package ‘ggplot2’ version 3.4.0 cannot be unloaded:
Error in unloadNamespace(package) : namespace ‘ggplot2’ is imported by ‘ggfun’, ‘ggplotify’, ‘ggimage’ so cannot be unloaded
Edit
Fresh start Rstudio
Open my R script file with following 3 lines:
sessionInfo()
library(ggplot2, lib.loc="~/R/ggplot336/")
ggimage::geom_image()
When I run the first line, sessionInfo() before doing anything else. We can see ggplot2_3.4.0 there. Could this be a Rstudio feature or an issue?
R version 4.2.2 Patched (2022-11-10 r83330)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.1 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.10.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0
locale:
[1] LC_CTYPE=en_AU.UTF-8 LC_NUMERIC=C LC_TIME=en_AU.UTF-8
[4] LC_COLLATE=en_AU.UTF-8 LC_MONETARY=en_AU.UTF-8 LC_MESSAGES=en_AU.UTF-8
[7] LC_PAPER=en_AU.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_AU.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] Rcpp_1.0.9 highr_0.9 pillar_1.8.1 compiler_4.2.2
[5] R.utils_2.12.2 R.methodsS3_1.8.2 yulab.utils_0.0.5 tools_4.2.2
[9] digest_0.6.30 evaluate_0.18 jsonlite_1.8.3 lifecycle_1.0.3
[13] tibble_3.1.8 gtable_0.3.1 ggimage_0.3.1 R.cache_0.16.0
[17] pkgconfig_2.0.3 rlang_1.0.6 reprex_2.0.2 DBI_1.1.3
[21] cli_3.4.1 ggplotify_0.1.0 rstudioapi_0.14 magick_2.7.3
[25] yaml_2.3.6 xfun_0.35 fastmap_1.1.0 knitr_1.41
[29] withr_2.5.0 dplyr_1.0.10 styler_1.8.1 generics_0.1.3
[33] vctrs_0.5.1 fs_1.5.2 gridGraphics_0.5-1 grid_4.2.2
[37] tidyselect_1.2.0 glue_1.6.2 R6_2.5.1 processx_3.8.0
[41] fansi_1.0.3 rmarkdown_2.18 clipr_0.8.0 callr_3.7.3
[45] ggplot2_3.4.0 purrr_0.3.5 magrittr_2.0.3 ps_1.7.2
[49] htmltools_0.5.3 scales_1.2.1 assertthat_0.2.1 colorspace_2.0-3
[53] utf8_1.2.2 munsell_0.5.0 ggfun_0.0.9 R.oo_1.25.0
It looks like R studio is loading in all of the previous libraries from a previous session. Maybe something leftover in .RData or .Rhistory. A fresh start of R should have far few loaded libraries.
Here is my fresh start:
sessionInfo()
R version 4.2.2 (2022-10-31)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Monterey 12.6.1
Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.2.2 tools_4.2.2
In Rstudio's preference you should see this screen:
I would try unchecking all of the boxes and then quit and restart Rstudio to see if that clears up the problem.
After some experiments, I kind of worked out the problem. Since this has consumed so much time of my time, I thought this could be helpful to others.
The problem is :: (double colon) with packages using ggplot2, such as ggimage in my example. It appears that RStudio automatically load some dependent packages when a script file is open. One way to fix this problem for my work now is to remove ::, but use library() then function (geom_image) instead.
This fixed my problem but I still don't understand why RStudio behaves this way.
If :: (double colon) is necessary, comment lines containing ::, then after loading older version of ggplot2, uncomment those lines. A little awkward, but it works for me.
I am unable to authenticate my googlesheets package. Everytime I run the gs_auth() command I am taken to the chrome where I would usually login to enable the package to access my googlesheets:
However, lately every time I do this I have the following error from Google:
Here my session information:
sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 9 (stretch)
Matrix products: default
BLAS/LAPACK: /usr/lib/libopenblasp-r0.2.19.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
[6] LC_MESSAGES=C LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices datasets utils methods base
other attached packages:
[1] googlesheets_0.3.0
loaded via a namespace (and not attached):
[1] Rcpp_1.0.2 crayon_1.3.4 dplyr_0.8.3 withr_2.1.2 assertthat_0.2.1 cellranger_1.1.0 R6_2.4.0
[8] magrittr_1.5 httr_1.4.1 pillar_1.4.2 rlang_0.4.1 cli_1.1.0 curl_4.2 renv_0.8.2-12
[15] rstudioapi_0.10 tools_3.6.1 glue_1.3.1 purrr_0.3.3 compiler_3.6.1 askpass_1.1 pkgconfig_2.0.3
[22] sessioninfo_1.1.1 openssl_1.4.1 tidyselect_0.2.5 tibble_2.1.3
gs_auth()
I have also followed the instructions given here on this stack overflow question. However still no luck.
I have been able to access my sheet using the googledrive package, however I'd still like to fix this.
Thanks!
googlesheets4 will replace googlesheets package very soon (by March 2020). Most of the functions performed by googlesheets can be handled by googlesheets4 currently, except for writing to specific cells.
googlesheets4 has a oauth authentication using Gargle (similar to googledrive package). More info can be found here - https://github.com/tidyverse/googlesheets4
Adding the answer from Jenny Bryan (maintainer of googlesheets and googlesheets4) from Github to this issue here:
"Default oauth app not working any more"
https://github.com/jennybc/googlesheets/issues/397
The link includes pretty detailed, step-by-step instructions, and I won't repeat what's she's already laid out really well. But quick version is you'll need to set up your own API credentials to make the oAuth client work. And remember, that will only help until March 2020.
Probably better, as #Kannan and others point out, is to make the switch to the new googlesheets4 package now if you can.
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
In doing final checks on a CRAN package submission, this NOTE comes up:
* checking top-level files ... NOTE
Files ‘README.md’ or ‘NEWS.md’ cannot be checked without ‘pandoc’ being installed.
However, pandoc is definitely installed as I use it regularly, and this package makes frequent use of it in documentation using pkgdown.
> rmarkdown::pandoc_available()
[1] TRUE
> rmarkdown::pandoc_version()
[1] ‘1.19.2.1’
I want to avoid installing pandoc from source because the latest version of pandoc supercedes the version installed with other R packages and causes weird output.
There is a similar question from a few years back but the solutions there are to either:
Install pandoc from source or via the installr package, whereas I already have pandoc installed; and,
Place the two files into .Rbuildignore, however both should be accepted with CRAN submissions now.
This note only comes up when checked using devtools::release() and when using devtools::check(check_version = TRUE), which otherwise passes with no warnings or notes.
The RStudio install of Pandoc:
Sys.getenv('RSTUDIO_PANDOC')
[1] "/Applications/RStudio.app/Contents/MacOS/pandoc"
Which I had previously exported to my ~/.bash_profile:
export PATH="$PATH:/Applications/Rstudio.app/Contents/MacOS/pandoc"
Any ideas?
> sessionInfo()
R version 3.4.3 (2017-11-30)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.2
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib
locale:
[1] en_CA.UTF-8/en_CA.UTF-8/en_CA.UTF-8/C/en_CA.UTF-8/en_CA.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] cancensus_0.1.6
loaded via a namespace (and not attached):
[1] Rcpp_0.12.14 rstudioapi_0.7 knitr_1.17 bindr_0.1
[5] xml2_1.1.1 magrittr_1.5 roxygen2_6.0.1 devtools_1.13.4
[9] R6_2.2.2 rlang_0.1.6 httr_1.3.1 stringr_1.2.0
[13] dplyr_0.7.4 tools_3.4.3 hunspell_2.9 git2r_0.20.0
[17] withr_2.1.1 htmltools_0.3.6 rversions_1.0.3 commonmark_1.4
[21] rprojroot_1.2 yaml_2.1.14 digest_0.6.13 assertthat_0.2.0
[25] tibble_1.3.4 crayon_1.3.4 bindrcpp_0.2 curl_3.1
[29] evaluate_0.10.1 memoise_1.1.0 glue_1.2.0 rmarkdown_1.8
[33] stringi_1.1.5 compiler_3.4.3 backports_1.1.0 desc_1.1.1
[37] jsonlite_1.5 pkgconfig_2.0.1
This happens because devtools::release calls devtools::check with check_version = TRUE.
You can also run devtools::check(check_version = TRUE) to trigger the same note.
I think for this part you would need pandoc on your PATH.
(indeed, after adding the existing ...\RStudio\bin\pandoc to my PATH the note is gone)
This question appears to be a duplicate.
Currently no accepted solution at the above linked Q. However, #hrbrmster's suggested solution in that thread: adding the README.md and NEWS.md to the .Rbuildignore remove the NOTES for me.
Current .RBuildignore contents
^pkg_name_here\.Rproj$
^\.Rproj\.user$
^cran-comments\.md$
^CODE_OF_CONDUCT\.md$
^README\.md$
^NEWS\.md$
I am using default command to install multicore package
install.packages('multicore','http://www.rforge.net/')
as written here http://www.rforge.net/multicore/files/ but I recieve warning:
install.packages('multicore','http://www.rforge.net/')
Warning in install.packages :
'lib = "http://www.rforge.net/"' is not writable
Would you like to use a personal library instead? (y/n) y
Warning in install.packages :
package ‘multicore’ is not available (for R version 3.1.2)
Does anybody know any solution to this? I can not use previous versions of R.
I would like to use mclapply function from that package.
Thanks for help.
My session info is:
> sessionInfo()
R version 3.1.2 (2014-10-31)
Platform: x86_64-redhat-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] stringi_0.4-1 ggplot2_1.0.0
loaded via a namespace (and not attached):
[1] colorspace_1.2-4 digest_0.6.8 grid_3.1.2 gtable_0.1.2
[5] MASS_7.3-35 munsell_0.4.2 plyr_1.8.1 proto_0.3-10
[9] Rcpp_0.11.3 reshape2_1.4.1 scales_0.2.4 stringr_0.6.2
[13] tools_3.1.2
Why do you need it?
Most of its functionality has been integrated into the parallel package which already comes with R. Have a look at its vignette, eg from within R via vignette() or else from here.
And the reason you cannot install 'multicore' is because it has been withdrawn by R Core, given how its functionality is (essentially entirely) in 'parallel' now.