Install own R package via function in R - r

When I build my own package in RStudio I click on "Install and restart" in the Build-tab. I'm wondering if I could do this via a function. I've seen that some code is running (meinpaket is the package's name):
Rcmd.exe INSTALL --no-multiarch --with-keep.source meinpaket
So I've tried the following:
system("Rcmd.exe INSTALL --no-multiarch --with-keep.source meinpaket")
I've tried it with shell, too.
I get the following error message:
Warning: invalid package 'meinpaket' Error: ERROR: no packages specified

You can zip your package (use the "build from source" command in RStudio to do the whole process including help and vignetts) and then install.packages() pointing to the zip file.

Related

R package installation error: "cannot remove earlier installation"

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()

Can not install processr and procesR on Windows

Following this question, I am trying to install the package (running R64 as admin on Windows):
devtools::install_github("markhwhiteii/processr")
or
devtools::install_github("cardiomoon/processR")
However, I get the error message:
Error: Failed to install 'processr' from GitHub:
(converted from warning) cannot remove prior installation of package 'digest'
no matter which update option I select. Running the command .libPaths() I found the packages installation folder C:/Program Files/R/R-3.6.2/library and manually deleted the digest package and reinstalled it with package.install("digest"). But I still get the same error! I would appreciate it if you could help me understand what is the problem and how I can resolve it.
The simplest solution is to say no when install_github asks if it should replace digest.
If it still fails for some reason (and I can't see why; neither package requires a specific version of digest and you've reinstalled it in any case), then the problem is that devtools itself uses digest, so it can't be removed as long as devtools is loaded. So you can't use install_github.
You have a couple of options:
Clone the repo, then from the command line, run R CMD INSTALL . in that directory. Note that you'll need to insert the path to your R executable.
Install from the GitHub archive of the master branch: install.packages("https://github.com/markhwhiteii/processr/archive/master.tar.gz")
The steps to install the markhwhiteii/processr package:
install.packages("devtools")
library(devtools)
install.packages("https://github.com/markhwhiteii/processr/archive/master.tar.gz")
for testing the instalation:
library(processr)
processr::model1
Sent a PR on the GitHub repo.
and if you want to run R in the Jupyter environment just follow the instructions to install and regsiter the kernel:
install.packages('IRkernel')
IRkernel::installspec()

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)

Github gpusvcalibration package installation in R

I am trying to install a package called gpusvcalibration from Github.
library("devtools")
install_github("mfrdixon/gpusvcalibration")
And I get the following error:
Error: Command failed (1)
Anyone know what is going on?
Have you read the installation instructions from the repo and followed them?
Clone the repository and then
Modify the R_EXE and R_INCLUDE variables in the Makefile
R CMD build gpusvcalibration
R CMD check gpusvcalibration
R CMD install gpusvcalibration_0.0-1.tar.gz
install.packages('gpusvcalibration_0.0-1.tar.gz', repo=NULL)

"installation of package 'FILE_PATH' had non-zero exit status" in R

By installing the package in R using the following command:
install.packages('FILE_PATH', repos=NULL, type = "source")
I got the following error:
Installing package into ‘/home/p/R/x86_64-pc-linux-gnu-library/3.0’
(as ‘lib’ is unspecified)
Errore in rawToChar(block[seq_len(ns)]) :
embedded nul in string: 'PK\003\004\024\0\002\0\b\0]\xadVCr\xcb\xea\xfcR\0\0\0\xa7\0\0\0\027\0\0\0bivpois-Rcode/.Rhistory+\xce/-JN\xd5PO\xca,+\xc8\xcf,\xd6+IL\xcaI\xd5\vR\xd7\xe4\xe5*\x86J\xe5\xe4\xea%\025`\b\xa5d\xa2\v楖\xe7%\xe6'
Warning message:
In install.packages("/home/p/Research/14_bivpois-Rcode.zip", repos = NULL, :
installation of package ‘/home/p/Research/14_bivpois-Rcode.zip’ had non-zero exit status
The R version is the 3.0.2 (2013-09-25) -- "Frisbee Sailing" and the OS is Linux Mint (UNIX).
Why Do I get that error and what does it mean:
installation of package ‘/home/p/Research/14_bivpois-Rcode.zip’ had non-zero exit status
in R?
You can find the package here and the file 14_bivpois-Rcode.zip is the source.
I tried to install that locally and the path is the correct one.
Any suggestion to install that package in UNIX?
Simple install following libs on your linux.
curl: sudo apt-get install curl
libssl-dev: sudo apt-get install libssl-dev
libcurl: sudo apt-get install libcurl4-openssl-dev
xml2: sudo apt-get install libxml2-dev
The .zip file provided by the authors is not a valid R package, and they do state that the source is for "direct use" in R (by which I assume they mean it's necessary to load the included functions manually). The non-zero exit status simply indicates that there was an error during the installation of the "package".
You can extract the archive manually and then load the functions therein with, e.g., source('bivpois.table.R'), or you can download the .RData file they provide and load that into the workspace with load('.RData'). This does not install the functions as part of a package; rather, it loads the functions into your global environment, making them temporarily available.
You can download, extract, and load the .RData from R as follows:
download.file('http://stat-athens.aueb.gr/~jbn/papers/files/14/14_bivpois_RDATA.zip',
f <- tempfile())
unzip(f, exdir=tempdir())
load(file.path(tempdir(), '.RData'))
If you want the .RData file to be available in the current working directory, to be loaded in the future, you could use the following instead:
download.file('http://stat-athens.aueb.gr/~jbn/papers/files/14/14_bivpois_RDATA.zip',
f <- tempfile())
unzip(f, exdir=tempdir())
file.copy(file.path(tempdir(), '.RData'), 'bivpois.RData')
# the above copies the .RData file to a file called bivpois.RData in your current
# working directory.
load('bivpois.RData')
In future R sessions, you can just call load('bivpois.RData').
You can try using command : install.packages('*package_name', dependencies = TRUE)
For example is you have to install 'caret' package in your R machine in linux : install.packages('caret', dependencies = TRUE)
Doing so, all the dependencies for the package will also be downloaded.
For those of you who are using MacOS and like me perhaps have been circling the internet as to why some R packages do not install here is a possible help.
If you get a non-zero exit status first check to ensure all dependencies are installed as well. Read through the messaging. If that is checked off, then look for indications such as gfortran: No such a file or directory. That might be due to Apple OS compiler issues that some packages will not install unless you use their binary version. Look for binary zip file in the package cran.r-project.org page, download it and use the following command to get the package installed:
install.packages("/PATH/zip file ", repos = NULL, type="source")
Did you check the gsl package in your system. Try with this:
ldconfig-p | grep gsl
If gsl is installed, it will display the configuration path. If it is not in the standard path /usr/lib/ then you need to do the following in bash:
export PATH=$PATH:/your/path/to/gsl-config
If gsl is not installed, simply do
sudo apt-get install libgsl0ldbl
sudo apt-get install gsl-bin libgsl0-dev
I had a problem with the mvabund package and this fixed the error
Cheers!
I was having a similar problem trying to install a package called AED. I tried using the install.packages() command:
install.packages('FILE_PATH', repos=NULL, type = "source")
but kept getting the following warning message:
Warning message:
In install.packages("/Users/blahblah/R-2.14.0/AED", :
installation of package ‘/Users/blahblah/R-2.14.0/AED’ had
non-zero exit status
It turned out the folder 'AED' had another folder inside of it that hadn't been uncompressed. I just uncompressed it and tried installing the package again and it worked.
Try use this:
apt-get install r-base-dev
It will be help. After then I could makeinstall.packages('//package_name')
I have had the same problem with a specific package in R and the solution was I should install in the ubuntu terminal libcurl.
Look at the information that appears above explaining to us that curl package has error installation.
I knew this about the message:
Configuration failed because libcurl was not found. Try installing:
* deb: libcurl4-openssl-dev (Debian, Ubuntu, etc)
* rpm: libcurl-devel (Fedora, CentOS, RHEL)
* csw: libcurl_dev (Solaris)
If libcurl is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a libcurl.pc file. If pkg-config
is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
To install it I used the net command:
sudo apt-get install libcurl4-openssl-dev
Sometimes we can not install a specific package in R because we have problems with packages that must be installed previously as curl package. To know if we should install it we should check the warning errors such as: installation of package ‘curl’ had non-zero exit status.
I hope I have been helpful
I had the same problem, but the answer from #little_chemist helped me sorting it out. When installing packages from a file in a unix OS (Ubuntu 18.04 for me), the file can not be zipped. You are using:
install.packages("/home/p/Research/14_bivpois-Rcode.zip", repos = NULL, type="source")
I noticed the solution was as simple as unzipping the package. Additionally, unzip all (installation related?) packages inside, as #little_chemist points out. Then use install.packages:
install.packages("/home/p/Research/14_bivpois-Rcode", repos = NULL, type="source")
Hope it helps!

Resources