R package installation error: "cannot remove earlier installation" - r

I'm currently making a R package (tessellation) which includes some C code. When I do some modifications and click "Install and restart" in RStudio, I get this error:
==> Rcmd.exe INSTALL --no-multiarch --with-keep.source tessellation
* installing to library 'C:/PortableApps/R/R-4.1.2/App/R-Portable/library'
* installing *source* package 'tessellation' ...
ERROR: cannot remove earlier installation, is it in use?
When I do "Restart R session" before "Install and restart", sometimes this works, sometimes not. So I have to close the project and reopen it, and this is annoying. Do you know what could I do to work more conveniently?

You need to be sure that the process is not being used (or loaded into R's search path) for the package. I suggest stopping all R sessions, deleting the installed package folder manually, start an R vanilla session, check the attached packages/search path, and finally attempt re-installation/building the package:
# from terminal
R --vanilla
# check search path
ls()
search()
# attempt installing package
devtools::install() # or devtools::build()

Related

devtools equivalent of RStudio Build panel buttons

I am making an R package using RStudio. I am comfortable using the buttons on the Build panel. I have a script that I would like to run each time I Build & Reload or Clean and Rebuild. I'd like to write a function that runs my script and then executes the devtools commands associated with one of those buttons, but I am having trouble finding documentation of the correspondence between those buttons and devtools commands. The buttons are as follows:
Build & Reload
Check
Load All
Clean and Rebuild
Test Package
Check Package
Build Source Package
Build Binary Package
For each of the items in that list, what devtools R code would I run to cause the exact same behavior?
In RStudio you can check "Use devtools package functions if available" in Project Options > Build Tools and you can see what devtools functions will be used. If you look at the build console pane, you can check out what RStudio runs. General cases if using devtools:
Build & Reload
devtools::build()
devtools::reload() is possibly an option but Rstudio uses R CMD INSTALL --no-multiarch --with-keep.source <pkgNameGoesHere>
Check
devtools::check()
Load All
devtools::load_all(".")
Clean and Rebuild
R CMD INSTALL --preclean --no-multiarch --with-keep.source <pkgNameGoesHere>
Test Package
devtools::test()
Check Package
devtools::check() (same as Check button)
Build Source Package
devtools::build()
Build Binary Package
devtools::build(binary = TRUE, args = c('--preclean'))
More info at the readme in the devtools repo.
To execute the Clean & Rebuilt action from RStudio inside R you can use the R function
system()
Executing
system("R CMD INSTALL
--preclean
--no-multiarch
--with-keep.source <your_package_name>")
Executes the Shell command from within your R session. Be aware that you will have to refer to the correct location of your package if you run this outside the Package Project (e.g. from another project or session)

Cannot install R packages in Jupyter Notebook

I am trying to run R code in Jupyter and the R Kernel was added. Most of the time, packages can be installed successfully. However, some of the packages, such as RCurl and ggmap, would got error while installing.
Example:
install.packages("RCurl")
Warning message in install.packages("RCurl"):
“installation of package ‘RCurl’ had non-zero exit status”Updating HTML index of packages in '.Library'
Making 'packages.html' ... done
What should I do?
Try to specify CRAN as repository in your install.packages statement when installing RCurl and ggmap. For example:
install.packages("RCurl", repos='http://cran.us.r-project.org')
This Stack Overflow post on installing R packages through Anaconda/Jupyter beyond those included in R essential provides more detail.
(Side note: I had encountered the same issue when trying to install R packages on computer clusters. This solution worked for me.)
use conda comment:
conda install r-RCurl
I kept getting the non-zero exit status when trying to install packages with Jupyter notebook with R kernel and was failing because of multiple dependencies when wanting to install a package. I am not an expert in any of these so please forgive me if I make an error in explaining or if it is a non-issue for you but please feel free to comment to clear things out. I just want to share my success story so hopefully it can help someone else: I am working on a MacBook Pro. Here are the information I get when I run R.version() on my jupyter notebook with R kernel:
$platform 'x86_64-conda_cos6-linux-gnu'
$arch 'x86_64'
$os 'linux-gnu'
$system 'x86_64, linux-gnu'
$language 'R'
$version.string 'R version 3.6.1 (2019-07-05)'
These are the steps to take to fix the issue:
Go to https://anaconda.org/
Search the package name that you are trying to install
Copy the one line that is given to install the package, it should be something like:
Conda install -c r r-caret #conda install -c r r-package_name
NOTE: sometimes during installing packages, you’re asked whether or not you want to continue, so add --y at the end of the above statement to continue, so something like this
Conda install -c r r-caret --y
(I will always add it just to be on the safe side)
Click on the new launcher (+ icon) to create a new notebook with PySpark (once opened it has .ipynp extension)
On the first cell paste the copied line from step 2 and run
Once done, restart the kernel on the current notebook
Restart the kernel on your other notebook with R kernel
Run library(package_name) on your notebook with R kernel (e.x. library(caret))
install.packages("Hmisc", .libPaths(), repos='http://cran.us.r-project.org')
This command will install the packagae in the conda
"/home/user/anaconda3/lib/R/library" and use the cran r repository as source.
Add path in Anaconda
As per this answer,
one can also add additional paths in anaconda to load libraries from (for eg., the location where R studio saves the user-installed packages) with
.libPaths( c( .libPaths(), "~/userLibrary") )
For example, the following worked for me:
In Anaconda :
.libPaths( c( .libPaths(), "C:\Users\name\Documents\R\win-library\3.5") )
When I tried to add anaconda's library path to RStudio, it resulted in errors (The procedure entry point MARK_NOT_MUTABLE could not be located in the dynamic link library << arose 4 times in succession) after installation of a package, though the package seemed to load.
Replace name with your local user folder name
Add/change path in RStudio
A useful link to make changes in default user-installed library paths :
https://www.accelebrate.com/library/how-to-articles/r-rstudio-library
To find out where a package has been installed:
find.package('package_name')
The directions nobody else supplied worked for me, but I found this guide, and it worked. Spent way too much time trying all these when I just needed a few simple commands. https://developers.refinitiv.com/en/article-catalog/article/setup-jupyter-notebook-r
I already had R and python installed, so I skipped to step 3. The only seems to mention windows, but it worked for me on mac as well. After following them I was able to install the packages using install.packages("dplyr", repos = "http://cran.us.r-project.org") in a cell in jupyter.
You have to create a directory in which your package will be and do for eg:
install.packages('ggplot2',loc='your directory')
First Step: You can install the IRkernel packages by running the following command in an R console:install.packages('IRkernel')
Second Step: You will have to make Jupyter see the newly installed R kernel by installing a kernel spec. To install system-wide, set user to False in the installspec command IRkernel::installspec(user = FALSE)
Setup Jupyter Notebook for R

Error in in installing an old version of a R package

I tryed to install from file an old version of RgoogleMaps package with this command
install.packages("F://RgoogleMaps_1.1.9.15.tar.gz", repos = NULL, type="source")
but i found this error message:
* installing *source* package 'RgoogleMaps' ...
** package 'RgoogleMaps' successfully unpacked and MD5 sums checked
ERROR: a 'NAMESPACE' file is required
* removing 'C:/Users/Famiglia Mazza/Documents/R/win-library/3.1/RgoogleMaps'
* restoring previous 'C:/Users/Famiglia Mazza/Documents/R/win-library/3.1/RgoogleMaps'
Warning in install.packages :
running command '"C:/PROGRA~1/R/R-31~1.2/bin/x64/R" CMD INSTALL -l "C:\Users\Famiglia Mazza\Documents\R\win-library\3.1" "F://RgoogleMaps_1.1.9.15.tar.gz"' had status 1
Warning in install.packages :
installation of package ‘F://RgoogleMaps_1.1.9.15.tar.gz’ had non-zero exit status
what can I do? I'm using R on Windows
In R 2.14.0 a requirement was made that all packages had namespaces, but as a transitional arrangement those that didn't would have one automatically generated at install time.
A package R code but without a ‘NAMESPACE’ file will have a default
one created at R CMD build or R CMD INSTALL time, so all packages will
be installed with namespaces. A consequence of this is that
.First.lib() functions need to be copied to .onLoad() (usually) or
.onAttach(). For the time being, if there is an auto-generated
‘NAMESPACE’ file and no .onLoad() nor .onAttach() function is found
but .First.lib() is, it will be run as the attach hook (unless the
package is one of a list of known exceptions, when it will be run as
the load hook).
However, by R 3.0.0 this transitional arrangement was ended:
The transitional support for installing packages without namespaces
(required since R 2.14.0) has been removed. R CMD build will still add
a namespace, but a .First.lib() function will need to be converted.
R CMD INSTALL no longer adds a namespace (so installation will fail),
and a .First.lib() function in a package will be ignored (with an
installation warning for now).
As an exception, packages without a ‘R’ directory and no ‘NAMESPACE’
file can still be installed.
Therefore, I suggest you use an older version of R to run this package. One prior to R 3.0.0 should suffice, and the latest one prior to that is R 2.15.3.

Error when installing R package using Rstudio

I want to install http://cran.r-project.org/src/contrib/Archive/mecdf/ using RStudio but when I use
> install.packages('C:\\Users\\jandre\\Desktop\\mecdf_0.6.1.tar.gz', repos=NULL, type="source")
I get this error:
Installing package into ‘C:/Users/jandre/Documents/R/win-library/3.1’
(as ‘lib’ is unspecified)
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
Warning in install.packages :
running command '"C:/Program Files/R/R-3.1.1/bin/x64/R" CMD INSTALL -l "C:\Users\jandre\Documents\R\win-library\3.1" "C:/Users/jandre/Desktop/mecdf_0.6.1.tar.gz"' had status 1
Warning in install.packages :
installation of package ‘C:/Users/jandre/Desktop/mecdf_0.6.1.tar.gz’ had non-zero exit status
This occurs in every package I want to install using the tar.gz file. I'm on Win7 x64. RStudio Version 0.98.1028
Can't think of a way to fix this at the moment -- sorry -- but the R administration manual says explicitly:
Note that installing R into a directory whose path contains spaces is not supported, and at least some aspects (such as installing source packages) will not work.
I don't know why this doesn't bite people much more often, given that C:/Program Files/... seems like a relatively normal place to install things on Windows.
I would also expect that the double quotation marks around your R executable name ("C:/Program Files/R/R-3.1.1/bin/x64/R") in the system call should have protected you from this problem ... ?
I had the same error message with the installation of some packages(under Windows 10 OS with R and Rstudio).
It seems that the R software (not R Studio) is dealing with the library where package are installed.
I uninstalled R and Rstudio and installed it a path without space (ex: C:\Program\R).I tried to load the packages that previously failed and it seemed to fix the problem.

problem when installing RTextTools for R

I was trying to install RTextTools package for R, but failed. Here is the output from the screen
> > install.packages("RTextTools")
Warning in install.packages("RTextTools") :
argument 'lib' is missing: using 'C:\Users\datamining\Documents/R/win-library/2.10'
--- Please select a CRAN mirror for use in this session ---
Warning: unable to access index for repository http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/2.10
Warning message:
In getDependencies(pkgs, dependencies, available, lib) :
package ‘RTextTools’ is not available
What's the reason for this problem, and how to fix it? Thanks.
There are two distinct, but related, issues:
You are running version 2.10 of R which is two years old. CRAN supports only the current version with pre-built binaries. You could try installing from source.
RTextTools, as can be seen on its CRAN page also requires at least R version 2.13.
So in short: you should upgrade.
I have resolved the issue. I have Download RTextTools From Given Link.

https://cran.r-project.org/src/contrib/Archive/RTextTools/
and copy RTextTools_1.4.2.tar.gz file in project root folder then run this command in project folder in terminal
"R CMD INSTALL RTextTools_1.4.2.tar.gz"
After running this command I receive below error
"ERROR: dependencies ‘SparseM’, ‘randomForest’, ‘tree’, ‘e1071’, ‘ipred’, ‘caTools’, ‘maxent’, ‘glmnet’, ‘tau’ are not available for package ‘RTextTools’".
Now install each dependencies from RStudio or RConsole (Any Editor used by you) by simply running this code.
install.packages("caTools").
Install all 9 required packages One By One (In My Case it was 9 Packages Dependencies required by RTextTools) all packages will be installed except 'maxent'.
Now download maxent from the given link.
https://cran.r-project.org/src/contrib/Archive/maxent/.
and copy maxent_1.3.3.1.tar file in project folder then run this command in project folder in terminal.
"R CMD INSTALL maxent_1.3.3.1.tar"
Now For RTextTools Run this command again in Terminal.
"R CMD INSTALL RTextTools_1.4.2.tar.gz"
All is done Now..
But the Last Step is
Load the RTextTools using.
library(RTextTools)
You will see one more Error: Load SparseM Now Loading SparseM use code below.
library(SparseM)
and in the last Load RTextTools
library(RTextTools)
RTextTools is dependent on a number of packages, most of which require R 2.13+. You should always keep R updated to the latest version, since each update contains numerous bug fixes and performance enhancements.
If you can't install packages from repository or the packages are not available anymore, just follow this steps:
Install.packages("devtools")
check -- library("devtools")
install_github("cran/maxent")
install_github("cran/RTextTools")

Resources