Changeing directory in R studio when installing packages - r

How do i choose the library which the package is install in in Rstudio?
When i run "install and restart" i get this error:
installing to library 'C:/Program Files/R/R-4.0.0/library'
Error: ERROR: no permission to install to directory 'C:/Program Files/R/R-4.0.0/library'
Exited with status 1.
I want it to install on "h:/r_packages"

As I understand you want to install your personal package. I don't find any option for the library path in RStudio. You can run this code in the console:
withr::with_libpaths("h:/r_packages", devtools::install())
You have to run this command when the current directory is the one of the package. Otherwise use the pkg argument of devtools::install to specify the package directory.

The second argument of install.packages is lib, which specifies the library directory.
The help reads:
lib
character vector giving the library directories
where to install the packages.
Recycled as needed.
If missing, defaults to the first element of .libPaths().
So, the below would work, though I cannot try on my end.
install.packages("package_name", lib="h:/r_packages")

Related

how does fix the error of "no packages specified problem" for compiling package in r?

I tried to install a package in R on the server. it recompiled from sources to install package but I see the following error:
'\pn-s\proj1\p_k\fsh'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.
Error: ERROR: no packages specified
the above path is my workspace that my package is in it.
Do you know how I can fix this problem?

syntax error near unexpected token - R package Install

I am trying to install an R package along with its dependencies. But it is throwing error.
$ install.packages(rvest_0.3.5.tar.gz, dependencies=True)
-bash: syntax error near unexpected token `rvest_0.3.5.tar.gz,'
I am new to R please help me how can I download this along with it dependencies.
Before this, I tried following
$ R CMD INSTALL rvest_0.3.5.tar.gz
* installing to library ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library’
ERROR: dependencies ‘httr’, ‘magrittr’, ‘selectr’ are not available for package ‘rvest’
But it failed with dependent packages are missing error. And obviously it is cumbersome to install the dependent packages manually. Hence I tried package.install
You need to run it with quotes and capital TRUE:
install.packages("rvest_0.3.5.tar.gz", dependencies = TRUE)
Note this will only work if you have unix-like system and the file is located in your current working directory (check with running getwd() from your R session). Otherwise you need to provide full path to the file (like "~/somefolder/mydata/rvest_0.3.5.tar.gz").
If you run Windows, then you need .zip file instead of .tar.gz.
If you are connected to internet, just run:
install.packages("rvest")

Anaconda R environment can't access libraries/packages when in R project of github repository

I have an R environment in Anaconda with all the packages I need and use. I added a private repository from github onto my pc using the conda CLI. The project files includes an renv folder as well a .Rproj file. When I try to open any of the R scripts in the project without opening the Rproj file to open the project, they all show up as blank, and when I try to open a csv file it says it doesn't exist. When I open the Rproject, I cannot access any of my libraries or packages that I usually have access to in R. When I tried to install a package in this environment, I got the error:
warning in system(paste(cmd, "shlib-clean")) : 'make' not found warning in system(cmd) : 'make' not found error: compilation failed for package 'pkgload' * removing 'c:/users/poona/<repo name>/renv/staging/1/pkgload'
What's going wrong? I just want to access the scripts of the repository and load the packages of my usual environment. Any help is appreciated!

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

How to set the library location of installed R packages

My issue is that the package path I installed in R terminal is different from where I installed in R-studio. So I'd like to change the install location. How can I do that ? Thanks
R terminal:
You can pass the lib argument to install.packages which specifies the library location.
See ?install.packages:
lib: character vector giving the library directories where to
install the packages. Recycled as needed. If missing,
defaults to the first element of ‘.libPaths()’.
Rstudio:
If you go to tools -> Install Packages, you can specify where to install your package in the dialog.

Resources