What is checked in while "Checking whether a package can be installed"? - r

I have persistent errors while checking if is possible to install a package I made. The error I see is that I don't have a package installed from the Rstudio builder. However, I do have it installed and it can be loaded (see below)
From R packages, the advice doesn't tell you what is going on:
Checking whether package ‘XYZ’ can be installed. R CMD check runs R
CMD install to make sure that it’s possible to install your package.
If this fails, you should run devtools::install() or RStudio’s Build &
Reload and debug any problems before continuing.
I followed the advice, it seemed to install another package, and it installed correctly. but still the devtools::check returned an ERROR.
There are some post here, about failing to pass the check. See the error message:
** R
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
Error: package or namespace load failed for ‘integration’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):
there is no package called ‘Matrix’
The problem is that the Matrix package is up to date (I reinstalled it to make sure). But in a CI test it builds correctly.
What is done when "testing if installed package can be loaded"?
I looked into the source of tools, but I couldn't make sense of what is doing.
It is running an internal .install_packages function while testing if test_load which seems to call base::library which seems to load the namespace.
Neither from Rstudio build window and from the command line and it can't build correctly using devtools::check. But I can check after:
R CMD build package
R CMD check package_X.Y.Z.tar.gz
Which resulted in only a NOTE
Relevant info, I moved some packages from one lib to another, which may have created some errors to packages that have compiled code. However I think it was just a few (~10) packages.
> library("Matrix")
> session_info("Matrix")
─ Session info ─────────────────────────────────────────────────────────────────────────────────────────────
setting value
version R version 3.5.1 (2018-07-02)
os Ubuntu 16.04.5 LTS
system i686, linux-gnu
ui RStudio
language en_US
collate en_US.UTF-8
ctype en_US.UTF-8
tz Europe/Madrid
date 2018-10-22
─ Packages ─────────────────────────────────────────────────────────────────────────────────────────────────
package * version date lib source
lattice 0.20-35 2017-03-25 [1] CRAN (R 3.5.0)
Matrix * 1.2-14 2018-04-09 [1] CRAN (R 3.5.1)
[1] /usr/lib/R/site-library
[2] /home/lrevilla/R/i686-pc-linux-gnu-library/3.5
[3] /usr/local/lib/R/site-library
[4] /usr/lib/R/library

Related

Unloading the package R6 2.2.0 in R 3.4.4

I am using R 3.4.4 in a very controlled environment in my company.
Basically I am having issues loading caret package:
Installation is successful with:
install.packages("caret", repos="http://cran.rstudio.com/", type= 'binary') - for windows
now when I try to load it, I get the below error:
library(caret)
Error: package or namespace load failed for ‘caret’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):
namespace ‘R6’ 2.2.0 is already loaded, but >= 2.2.2 is required
In addition: Warning message:
package ‘caret’ was built under R version 3.4.4
I have both R6 2.2.0 and R6 2.4.0 installed in my library. However, if I try to uninstall R6 2.2.0, I get the below error:
Error in value[[3L]](cond) :
Package ‘R6’ version 2.2.0 cannot be unloaded:
Error in unloadNamespace(package) : namespace ‘R6’ is imported by ‘mrsdeploy’, ‘CompatibilityAPI’ so cannot be unloaded
In addition: Warning message:
package ‘R6’ was built under R version 3.4.4
Help please. Thanks in advance.
Package dependencies are to blame: if the package cannot be unloaded because another package has imported some of its functions, then you need to first unload that package. In this case, the mrsdeploy and CompatibilityAPI packages should be removed first. Note that this might be recursive, since anything that has imported anything from either of those packages will need to be unloaded.
The suggestion was made to restart with a clean R session, and you said that it did not work. I suggest that you restarted R, but it was not a clean R session: if there is an .Rdata file or a project file that automatically loads the previous session's data and/or libraries, then a clean session starts ... pre-cluttered. In that case, you can work around it by starting R manually (perhaps not in RStudio or your preferred IDE) as R --no-restore, as that should not restore (well named!) the .Rdata file.

Error: package or namespace load failed for 'treesnip'

When trying to install the treesnip package from github using remotes::install_github("curso-r/treesnip"), I get the following error:
remotes::install_github("curso-r/treesnip")
Downloading GitHub repo curso-r/treesnip#HEAD
WARNING: Rtools is required to build R packages, but is not currently installed.
Please download and install Rtools 4.0 from https://cran.r-project.org/bin/windows/Rtools/.
√ checking for file 'C:\Users\SAR.V-LOG\AppData\Local\Temp\RtmpENiM7Q\remotes38701dfb49f3\curso-r-treesnip-c70a89b/DESCRIPTION' (375ms)
- preparing 'treesnip': (736ms)
√ checking DESCRIPTION meta-information ...
- checking for LF line-endings in source and make files and shell scripts
- checking for empty or unneeded directories
Removed empty directory 'treesnip/.github/workflows'
Removed empty directory 'treesnip/.github'
NB: this package now depends on R (>= 3.5.0)
WARNING: Added dependency on R >= 3.5.0 because serialized objects in serialize/load version 3 cannot be read in older versions of R. File(s) containing such objects: 'treesnip/inst/benchmark_parallel_processing_vignette.rds'
- building 'treesnip_0.1.0.tar.gz'
* installing *source* package 'treesnip' ...
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
converting help for package 'treesnip'
finding HTML links ... done
add_boost_tree_catboost html
add_boost_tree_lightgbm html
add_decision_tree_tree html
multi_predict._catboost.Model html
multi_predict._lgb.Booster html
predict_lightgbm_classification_class html
predict_lightgbm_classification_prob html
predict_lightgbm_classification_raw html
predict_lightgbm_regression_numeric html
train_catboost html
train_lightgbm html
train_tree html
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
*** arch - i386
Error: package or namespace load failed for 'treesnip':
.onLoad failed in loadNamespace() for 'treesnip', details:
call: NULL
error: The values passed to `set_encoding()` are missing arguments: 'allow_sparse_x'
error: loading failed
running stopped
*** arch - x64
Error: package or namespace load failed for 'treesnip':
.onLoad failed in loadNamespace() for 'treesnip', details:
call: NULL
error: The values passed to `set_encoding()` are missing arguments: 'allow_sparse_x'
Fejl: loading failed
running stopped
ERROR: loading failed for 'i386', 'x64'
* removing 'C:/Users/SAR.V-LOG/OneDrive - VELUX/Documents 1/R/R-4.0.2/library/treesnip'
Error: Failed to install 'treesnip' from GitHub:
(converted from warning) installation of package ‘C:/Users/SAR~1.V-L/AppData/Local/Temp/RtmpENiM7Q/file38706c2c7239/treesnip_0.1.0.tar.gz’ had non-zero exit status
my sessionInfo():
sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)
Matrix products: default
locale:
[1] LC_COLLATE=Danish_Denmark.1252 LC_CTYPE=Danish_Denmark.1252 LC_MONETARY=Danish_Denmark.1252
[4] LC_NUMERIC=C LC_TIME=Danish_Denmark.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.0.2 tools_4.0.2
I works fine when running on another PC.
I also tried changing the library location to C:/Users/SAR.V-LOG/, but that didn't help either.
Further I tried to provide INSTALL_opts = "--no-test-load". When I do that the installation finished wihtout errors, but when I try to load the library using library(treesnip) I get the same error: The values passed to set_encoding() are missing arguments: 'allow_sparse_x'
Do you know what is causing this error and how I can fix it?
treesnip is fixed. It now depends on parsnip (>= 0.1.3.9000) https://github.com/curso-r/treesnip/commit/902a33d9f156c10da6dbe1bd9cccb65926077197
Try using parsnip 0.1.3 (not the development version in this case). It looks like 0.1.3.9000 has some breaking changes coming that will be handled in a new version of parsnip-adjacent packages.
The warning message indicates:
Please download and install Rtools 4.0 from https://cran.r-project.org/bin/windows/Rtools/.
You may need to upgrade your Rtools, which can be done here: https://cran.r-project.org/bin/windows/Rtools/
Let me know if this fixes your problem.
Also I have added a GitHub Issue Here: https://github.com/tidymodels/parsnip/issues/376

R package updates

I have been having some issues accessing an updated version of a package in R.
On running a workflow for data analysis I got this error message:
library(dplyr)
Error: package or namespace load failed for ‘dplyr’ in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]):
namespace ‘rlang’ 0.2.1 is already loaded, but >= 0.2.2 is required
I therefore tried to update both the "dplyr" and "rlang" packages.
On updating I get the messages:
Installing package into ‘C:/Users/tomsp/OneDrive/Documents/R/win-library/3.5’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
trying URL 'https://cran.ma.imperial.ac.uk/bin/windows/contrib/3.5/rlang_0.2.2.zip'
Content type 'application/zip' length 820944 bytes (801 KB)
downloaded 801 KB
package ‘rlang’ successfully unpacked and MD5 sums checked
Warning: cannot remove prior installation of package ‘rlang’
The downloaded binary packages are in
C:\Users\tomsp\AppData\Local\Temp\RtmpmooXKa\downloaded_packages
However if I check the package using the code below it still has version 0.2.1
packageVersion("rlang")
[1] ‘0.2.1’
I checked my library paths and still have not managed to be run the latest version(0.2.2) of the package rlang.
Any advice of what I am doing wrong or how I can solve this?
Restart R and run install.packages again. On Windows, you can't update a package that's already loaded, if the package contains compiled C/C++/Fortran code. This includes dplyr and rlang.
To be doubly sure, before you run install.packages, go to your R packages directory (C:/Users/tomsp/OneDrive/Documents/R/win-library/3.5) and delete any zero-length files that are present. These are artifacts of failed install attempts and will break install.packages if present.
For any reason, at least in Windows, some R processes may still be running in background. Close your current R session, kill all processes related to R and try again.
If you are using Windows, check if the package you are trying to upgrade is available only as a source file.
If you try to install a package that needs compilation, you need the software Rtools. Download it on cran.r-project.org/bin/windows/Rtools/. Updating Rtools might also resolve your problem. The console message for a particular package is like that:
binary source needs_compilation
backports 1.2.0 1.2.1 TRUE
On Linux you don't need Rtools, but read the console output when you see an error when you try to install or update a package. If some software is missing, the error message on Linux is self-explanatory.
Deleted the entire library from R packages directory on my local computer. Installed again after terminating the session. Worked for me.

dependency ‘slam’ is not available when installing TM package

I was able to use the library(tm) in r without problem until today, when loading tm shows:
library(tm)
Loading required package: NLP
Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) :
there is no package called ‘slam’
Error: package or namespace load failed for ‘tm’
I thought this is a dependency issue and seek to reinstall package
install.packages("tm")
Warning in install.packages : dependency ‘slam’ is not available
and then try to find slam:
install.packages("slam")
Warning in install.packages :
package ‘slam’ is not available (for R version 3.2.4)
I also tried some of the issues listed here and chooseCRANmirror(), still no luck. Is there something wrong with the package or is it just that my r does not allow 'slam' to install after today?
session info
> sessionInfo()
R version 3.2.4 (2016-03-10)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.6 (El Capitan)
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
other attached packages:
[1] NLP_0.1-9
loaded via a namespace (and not attached):
[1] parallel_3.2.4 tools_3.2.4
For R-version 3.2.3, following worked fine as mentioned in this link and it suggests this works for R-version 3.3.0 as well:
#install devtools if you have not installed
install.packages('devtools')
library(devtools)
slam_url <- "https://cran.r-project.org/src/contrib/Archive/slam/slam_0.1-37.tar.gz"
install_url(slam_url)
I found a hint at this german site about R under Install additional R packages ("Zusätzliche R-Pakete installieren")
After I installed slam seperatly over apt-get for example:
sudo apt-get install r-cran-slam
I could install tm the normal way:
install.packages('tm')
And load the library aswell.
I hope my answer helps someone.
I had the same problem as you.
Slam "Depends: R (≥ 3.3.1)", this why I had to perform the following actions to successfully install and load "tm" package:
Update R from 3.2.5 to the latest version 3.3.2
install.packages("tm")
also installing the dependencies ‘NLP’, ‘slam’
package ‘NLP’ successfully unpacked and MD5 sums checked
package ‘slam’ successfully unpacked and MD5 sums checked
package ‘tm’ successfully unpacked and MD5 sums checked
library(tm)
I used the following code to install the binary or the older version of slam. It worked for me.
install.packages("slam", type = "binary")
I had the same problem and:
I upgraded RStudio to the latest version (1.0.143)
I upgraded R to the latest version (R.3.3.3)
I rebooted Rstudio
I installed again in RStudio the package "tm"
I ran library(tm)
and everything works fine now.
The latest version of the package "slam" only works for R(>=3.4.0),so you can try either updating your R to the latest version or downloading an early version of the "slam" package.
This is a download link from CRAN for early version of "slam" package: https://cloud.r-project.org/bin/macosx/mavericks/contrib/3.3/slam_0.1-40.tgz.
Apparently the problem seems to be the version of R you are using. Try installing the latest version of R, 3.3.1. That should take care of it.
I am using R3.2.5. I was trying to install "tm". I did install NLP as a dependency but gave me an error :
"package ‘slam’ is not available (for R version 3.2.5)"
The option I had to was to download the zip/tar/gz file(binaries) from https://cran.r-project.org/web/packages/slam/index.html and install the package.
It worked for me after that. Although I am not sure what the problem is because the library information mentions it is for R (≥ 3.3.1)
I also had to upgrade to the most recent version of R.
Specifically, on Ubuntu 16.04 here are instructions to get the up to date R version.
I faced this error while installing the "tm" package on R version 3.3.0. Seems like some missing libraries. After I could install the latest version 3.4.1 , i was able to install the package "tm" which installed the 'slam' on its own. Hope this may help somebody.
Just Install NLP package with dependencies = True
Install tm packaged with dependencies = True
And things should work out:)
For Ubuntu, I installed the following two from console and then it got installed.
sudo apt-get install libblas-dev liblapack-dev
sudo apt-get install gfortran
For any such type of issue regarding package not installed, update your R and later reinstall the package. These are the steps you follow:
if(!require(installr)){ install.packages("installr")}
require(installr)} #load the package
updateR()

R within Rstudio cannot find rmarkdown package

I am trying to use rmarkdown, within Rstudio (0.98.953) on a PC, for the first time. I have upgraded to the latest versions of R (3.1.1) and R studio. The output from sessionInfo() is provided at the end of this question.
As I understand it rmarkdown should be included within Rstudio. However, when I select to create a markdown document in Rstudio, a dialog box pops up saying additional packages need to be installed. The installation of rmarkdown always then fails, with the following message:
Installing package into '\\cfsk18.campus.gla.ac.uk/SSD_Home_Data_X/jm383x/My Documents/R/win-library/3.1'
(as 'lib' is unspecified)
* installing *source* package 'rmarkdown' ...
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
*** arch - i386
Warning in library(pkg_name, lib.loc = lib, character.only = TRUE, logical.return = TRUE) :
there is no package called 'rmarkdown'
Error: loading failed
Execution halted
*** arch - x64
Warning in library(pkg_name, lib.loc = lib, character.only = TRUE, logical.return = TRUE) :
there is no package called 'rmarkdown'
Error: loading failed
Execution halted
ERROR: loading failed for 'i386', 'x64'
* removing '\\cfsk18.campus.gla.ac.uk/SSD_Home_Data_X/jm383x/My Documents/R/win- library/3.1/rmarkdown'
Warning messages:
1: running command '"C:/PROGRA~1/R/R-31~1.1/bin/x64/R" CMD INSTALL -l "\\cfsk18.campus.gla.ac.uk\SSD_Home_Data_X\jm383x\My Documents\R\win-library\3.1" "C:/PROGRA~1/RStudio/R/packages/rmarkdown_0.2.49_047a80058bb4ef0b142196013d1c4dd8870d4dd9.tar.gz"' had status 1
2: In utils::install.packages("C:/Program Files/RStudio/R/packages/rmarkdown_0.2.49_047a80058bb4ef0b142196013d1c4dd8870d4dd9.tar.gz", :
installation of package 'C:/PROGRA~1/RStudio/R/packages/rmarkdown_0.2.49_047a80058bb4ef0b142196013d1c4dd8870d4dd9.tar.gz' had non-zero exit status
I assume this is something to do with using a managed desktop in my place of work. However this is not usually a problem as far fewer restrictions are placed on these machines than is usually the case, and all other packages, software etc tend to work.
I have also tried installing rmarkdown directly from github. Again the installer cannot identify the package rmarkdown itself.
What is likely to be the cause of the error?
SessionInfo output:
R version 3.1.1 (2014-07-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252 LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C LC_TIME=English_United Kingdom.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] tools_3.1.1
Attempt to install directly from github repo:
devtools::install_github("rstudio/rmarkdown")
Installing github repo rmarkdown/master from rstudio
Downloading master.zip from https://github.com/rstudio/rmarkdown/archive/master.zip
Installing package from C:\Users\jm383x\AppData\Local\Temp\RtmpINmLRv/master.zip
Installing rmarkdown
Installing dependencies for rmarkdown:
httpuv
Installing package into ‘\\cfsk18.campus.gla.ac.uk/SSD_Home_Data_X/jm383x/My Documents/R/win-library/3.1’
(as ‘lib’ is unspecified)
trying URL 'http://cran.rstudio.com/bin/windows/contrib/3.1/httpuv_1.3.0.zip'
Content type 'application/zip' length 857357 bytes (837 Kb)
opened URL
downloaded 837 Kb
package ‘httpuv’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\jm383x\AppData\Local\Temp\RtmpINmLRv\downloaded_packages
"C:/PROGRA~1/R/R-31~1.1/bin/x64/R" --vanilla CMD INSTALL \
"C:\Users\jm383x\AppData\Local\Temp\RtmpINmLRv\devtoolscec10833677\rmarkdown-master" \
--library="\\cfsk18.campus.gla.ac.uk/SSD_Home_Data_X/jm383x/My Documents/R/win- library/3.1" --install-tests
* installing *source* package 'rmarkdown' ...
** R
** inst
** tests
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
*** arch - i386
Warning in library(pkg_name, lib.loc = lib, character.only = TRUE, logical.return = TRUE) :
there is no package called 'rmarkdown'
Error: loading failed
Execution halted
*** arch - x64
Warning in library(pkg_name, lib.loc = lib, character.only = TRUE, logical.return = TRUE) :
there is no package called 'rmarkdown'
Error: loading failed
Execution halted
ERROR: loading failed for 'i386', 'x64'
* removing '\\cfsk18.campus.gla.ac.uk/SSD_Home_Data_X/jm383x/My Documents/R/win- library/3.1/rmarkdown'
Try running this code to get the latest version of the rmarkdown package, which should solve the issue:
install.packages("rmarkdown", repos = "https://cran.revolutionanalytics.com")
The issue is that the RStudio IDE looks at a static CRAN snapshot that was taken before the rmarkdown package was updated. For more information, see this link: https://groups.google.com/forum/#!topic/rropen/Kgg8z6FF40I
I wonder if the problem is the space in the path shown for the --library option to your install_github command. I know you say you've installed packages OK before, but my setup sounds just slike yours and rmarkdown works for me. I have RStudio 0.98.953 on Win7, which is a very locked-down corporate machine. I've coerced it into letting me install R packages by setting the env variable R_LIBS to my network home drive. Loading packages is slow, but I have no choice because I cannot write to the C: drive. So, my install_github command has --library="H:/Rlib". Your path has "My Documents" embedded in it. I'm not positive that's the problem, but my github installation of "rstudio/rmarkdown" did succeed. When I do File -> New File -> R Markdown, followed by a press of the "Knit HTML" button, that also completes successfully.
The RStudio github page https://github.com/rstudio/rmarkdown#installation makes it sound like manual installation of rmarkdown in RStudio isn't required, but I did it anyway because I don't always use R through RStudio. Sorry, but I didn't test RStudio by making a new R Markdown file before I manually installed the package.
The RStudio blog post http://blog.rstudio.org/2014/06/18/r-markdown-v2/ says clearly that the rmarkdown package is intended to replace the previous markdown package. The rmarkdown package does not yet appear to be on CRAN, so install_github is necessary.
The best that worked for me is to quit Rstuido, then install rmarkdown package in the base R (not any IDE) and restarting Rstudio.
I am on Windows 10, R 3.3.1, Rstudio Version 0.99.903

Resources