I'm distributing an R package that requires other packages. If any are missing I get (for example) the following error:
library(whSample)
Error: package or namespace load failed for ‘whSample’ in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]):
there is no package called ‘dplyr’
I have code to check and install dependencies in the whSample package, but R fails before it gets to it when it sees the import(dplyr) in NAMESPACE. Here's the first block of code when the package function is called:
is_installed <- function(mypkg) is.element(mypkg, installed.packages()[,1])
whInstall <- function(pkgNames){
for(pkg in pkgNames){
if(!is_installed(pkg)){
install.packages(pkg, repos="http://lib.stat.cmu.edu/R/CRAN")
}
suppressMessages(suppressWarnings(
library(pkg, character.only=T, quietly=T, verbose=F)))
}
}
whInstall(c("magrittr","tools","purrr","openxlsx","data.table","dplyr","glue"))```
How can I get R to do these checks without running afoul of NAMESPACE?
A short answer is that you can ask people to install with
devtools::install_local("your-package.tar.gz")
What's happening behind the scene is that install.packages ignores the dependencies option when installing from a local file. It somehow assumes that the repository from which your are installing the package should also have the dependent packages. But for local files there is no repository, hence no dependency handling occurs.
When you install the package from a local file, install is going to search for dependencies on the same local path... and won't find them.
To get the CRAN dependecies automatically installed, you can use :
install.packages("devtools")
devtools::install_local("MypackageName.zip")
Related
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.
I am trying to install kableExtra and get the following errors:
Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck =
vI[[j]]) :
there is no package called 'hms'
ERROR: lazy loading failed for package 'kableExtra'
*removing 'C:/Users/Tim/Documents/R/win-library/3.2/kableExtra'
Warning in install.packages :
running command '"C:/PROGRA~1/R/R-32~1.5/bin/x64/R" CMD INSTALL -l "C:\Users\Tim\Documents\R\win-library\3.2"
C:\Users\Tim\AppData\Local\Temp\RtmpUJQfwD/downloaded_packages/kableExtra_0.9.0.
tar.gz' had status 1
Warning in install.packages :
installation of package ‘kableExtra’ had non-zero exit status
The downloaded source packages are in
‘C:\Users\Tim\AppData\Local\Temp\RtmpUJQfwD\downloaded_packages’
How can I solve my problem? Thanks in advance!
it seems kableExtra depends on the package "hms" so try install it before with:
install.packages("hms")
or via rstudio interface:
packages -> install
and type in "hms"
also try this command:
install.packages("kableExtra", dependencies = TRUE)
If there appear problems like installing rlang or something similar, there is no general solution for this. You can try to (re)install rtools. Sometimes there are missing parts of r installations. My guess if R can't install a dependencie is, that some library or tools of the R environment are missing or wrongly installed which have to be detected.
You have a trouble with the dependency with the package "hms". I have not got how you are installing the r package, but you can either install it first and then try it again or start the installation with the option of download and install all required dependencies, in the second option you need to be online and allow the package manager to intall what is required.
Here is how it looks in RGui. I guess your are not using RGui.
I had everything working with R and RStudio, but then I moved the folders when cleaning up my computer directories & files. Now I'm getting the error message below.
Should R and RStudio be installed under Program Files or Program Files (x86)? Should I have two libPaths?
install.packages("C:/Users/kevin/Downloads/fpp_0.5.zip", repos = NULL)
## Warning in install.packages :
## package ‘C:/Users/kevin/Downloads/fpp_0.5.zip’
## is not available (for R version 3.0.0)
## Installing package into ‘C:/Users/kevin/Documents/R/win-library/3.0’
## (as ‘lib’ is unspecified)
## package ‘fpp’ successfully unpacked and MD5 sums checked
library("fpp", lib.loc="C:/Users/kevin/Documents/R/win-library/3.0")
Loading required package: forecast
## Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) :
## there is no package called ‘colorspace’
## Error: package ‘forecast’ could not be loaded
When you install the package using the RStudio package installer or directly from CRAN, it doesn't install the dependencies ("fracdiff", "Rcpp", "RcppArmadillo" and "colorspace") and hence, R keeps throwing the load namespace error. Installing the package through, automatically installs all the dependencies and solves this problem.
install.packages("forecast",
repos = c("http://rstudio.org/_packages",
"http://cran.rstudio.com"))
The last time I encountered a very similar problem, I used this code which I got somewhere:
install.packages("package's name", repos=c("http://rstudio.org/_packages", "http://cran.rstudio.com"))
simply put your package's name in the quotation marks.
Hope this helps.
Use this:
install.packages("colorspace", dependencies = TRUE)
I ran into this problem. It turned out that my .Rprofile had calls to a package that was not installed. Removing these lines allowed installation to proceed normally.
I got this error while installing the library 'tidyverse'. Removed the error by upgrading R from v3.4 to v3.6
I try to test my package developed on Ubuntu 16.04 with Windows 7. For both platforms I work on R 3.3.1 (but I also test on 3.3.0).
My package is saved on my GitHub repo (https://github.com/charlottesirot/elementR). When I run this command from Ubuntu, no problem happens:
library(devtools)
install_github("charlottesirot/elementR", dependencies = T , force = T)
but with windows 7, I have the following answer:
Downloading GitHub repo charlottesirot/elementR#master from URL
https://api.github.com/repos/charlottesirot/elementR/zipball/master
Installing elementR "C:/PROGRA~1/R/R-33~1.1/bin/i386/R" --no-site-file
--no-environ --no-save --no-restore --quiet CMD \ INSTALL \ "C:/Users/Cha/AppData/Local/Temp/RtmpUX1GVA/devtoolsa907a336b/charlottesirot-elementR-103e064"
\ --library="C:/Users/Cha/Documents/R/win-library/3.3"
--install-tests
installing source package 'elementR' ...
** R
** inst
** preparing package for lazy loading Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) : there is no
package called 'XML' ERROR: lazy loading failed for package 'elementR'
removing 'C:/Users/Cha/Documents/R/win-library/3.3/elementR' Error: Command failed (1)
As I understand, R tries to install the dependencies of my package (e.g. Shiny...) but it does not manage to install the dependencies of the dependencies (e.g. XML from gnumeric package)
Thus I try to manually install XML thinking that perhaps there was a problem with XML and then:
installing source package 'elementR' ...
** R
** inst
** preparing package for lazy loading Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) : there
is no package called 'gtools' ERROR: lazy loading failed for package
'elementR'
removing 'C:/Users/Cha/Documents/R/win-library/3.3/elementR'
I cannot install all the packages manually, it does not make sense !!!
Moreover when I try something less cryptic than my package, thinking that I could makea mistake in my code:
install_github("hadley/ggplot2", force = T)
installing source package 'ggplot2' ...
** R
** data
*** moving datasets to lazyload DB
** inst
** tests
** preparing package for lazy loading Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) : there is no package called 'assertthat' ERROR: lazy loading failed for package 'ggplot2'
removing 'C:/Users/Cha/Documents/R/win-library/3.3/ggplot2'
restoring previous 'C:/Users/Cha/Documents/R/win-library/3.3/ggplot2' Error: Command failed (1
)
I think there is a problem from the install_github ???
What do you think ??
Here is my Namespace:
exportPattern("^[[:alpha:]]+")
importFrom(R6, R6Class)
importFrom(shinyjs, colourInput)
importFrom(shinyjs, delay)
importFrom(shinyjs, useShinyjs)
importFrom(gnumeric, read.gnumeric.sheet)
importFrom(abind, abind)
importFrom(tcltk2, tk2text)
importFrom(gdata, read.xls)
importFrom("readODS", read.ods)
importFrom("grDevices", "bmp", "colorRampPalette", "dev.off", "jpeg",
"png", "rainbow", "tiff")
importFrom("graphics", "abline", "layout", "legend", "mtext", "par",
"plot", "points", "rect", "text", "title")
importFrom("stats", "sd")
importFrom("utils", "read.table", "write.csv", "write.table")
import(shinydashboard, shiny, stringr, lmtest, reader, devtools, tcltk)
For me, it looks ok but what do you think ?
I looked at a lot of article on internet but I only found one message which is exactly the same than my case but it is not enough informative :
Cannot install "flexdashboard package"
I am totally stuck at this point and I would like to have your help regarding this issue.
Thank you verrrrrry much in advance !!
CHa
Recently, I encountered a similar or maybe related issue. As it turned out, there was a bug in devtools install_github, missing the correct installation of dependencies, despite dependecies=TRUE. Have a look at: Does install_github recursively install dependencies? If the problem persists, better contact the authors directly via their github repository.
Plus, I just observed another issue arising after a Windows update, during which permissions seemed to have been altered to download or update packages into personal Win User libraries instead of the "default" R library folder. I suspect devtools seemed consequently lost as to which packages were loaded or available at which versioning. A fresh R reinstallation (i.e., library folder cleansing) solved that issue, but such may not always be convenient.
I had everything working with R and RStudio, but then I moved the folders when cleaning up my computer directories & files. Now I'm getting the error message below.
Should R and RStudio be installed under Program Files or Program Files (x86)? Should I have two libPaths?
install.packages("C:/Users/kevin/Downloads/fpp_0.5.zip", repos = NULL)
## Warning in install.packages :
## package ‘C:/Users/kevin/Downloads/fpp_0.5.zip’
## is not available (for R version 3.0.0)
## Installing package into ‘C:/Users/kevin/Documents/R/win-library/3.0’
## (as ‘lib’ is unspecified)
## package ‘fpp’ successfully unpacked and MD5 sums checked
library("fpp", lib.loc="C:/Users/kevin/Documents/R/win-library/3.0")
Loading required package: forecast
## Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) :
## there is no package called ‘colorspace’
## Error: package ‘forecast’ could not be loaded
When you install the package using the RStudio package installer or directly from CRAN, it doesn't install the dependencies ("fracdiff", "Rcpp", "RcppArmadillo" and "colorspace") and hence, R keeps throwing the load namespace error. Installing the package through, automatically installs all the dependencies and solves this problem.
install.packages("forecast",
repos = c("http://rstudio.org/_packages",
"http://cran.rstudio.com"))
The last time I encountered a very similar problem, I used this code which I got somewhere:
install.packages("package's name", repos=c("http://rstudio.org/_packages", "http://cran.rstudio.com"))
simply put your package's name in the quotation marks.
Hope this helps.
Use this:
install.packages("colorspace", dependencies = TRUE)
I ran into this problem. It turned out that my .Rprofile had calls to a package that was not installed. Removing these lines allowed installation to proceed normally.
I got this error while installing the library 'tidyverse'. Removed the error by upgrading R from v3.4 to v3.6