I have installed an R project on a network. It automatically installs the library in the C:\Users\\AppData\Local\Temp\downloaded_packages, however, I would like to install the library to lets say Q:\Apps\R-Project\Libraries.
I managed to install the library to the Q network using the following command:
install.packages("dplyr", lib="Q:\Apps\R-Project\Libraries", dependencies=T)
When I load the library it says that it cannot find the Rccp.
Any help how to solve that issue?
You told R to install the package in a certain location, namely Q:\Apps\R-Project\Libraries.
When you tell R to use a certain package, R will not search your entire computer whether that package exists. Usually, the packages are being saved in a standard location that R knows and where R will also search for it, once you tell it to use that package. You can view these locations with .libPaths().
If Q:\Apps\R-Project\Libraries is not a location that you have saved in .libPaths(), you have two options:
# 1) Add it to `.libPaths()` like this:
.libPaths( c( .libPaths(), "Q:\Apps\R-Project\Libraries") )
# 2) Tell `R` explicitly where to look while loading the package:
library(packagename, lib.loc = "Q:\Apps\R-Project\Libraries")
I recommend using option 1
Related
Using R version 3.6.2, RStudio version 1.2.5033, Windows 10
I am compiling a report in Rmarkdown, and am finished except for some troubleshooting with the packages, specifically, those that need compilation and are delivered as binary format into a temp folder outside my working directory.
I am able to extract and copy these binary package contents individually to my library folder on my machine, but generally assume those reading the report will not have all the packages already installed.
Normally I handle packages requirements as follows:
# Install from github if not present
if (!require(devtools)) {
install.packages("devtools", dependencies = TRUE)
}
# Install from CRAN if not present
if (!require(installr)) {
install.packages("installr", dependencies = TRUE)
}
# Now we can use abbreviated require2 function for remainder
installr::require2(stringi, ask = FALSE, dependencies = TRUE)
.
.
.
What I am having trouble with is that 'stringi' package wants compilation upon running command for a machine without this package, and if I select 'no,' then it downloads as binary to a temporary folder. I then need to extract this manually outside of RStudio, which I don't want others to have to do.
So, is there a way to automate this process? Is there a better approach to what my aim is here that removes the issue altogether?
Thank you in advance for your insights and your patience (this is my first question).
I just need to solve a problem with my RStudio. I have the lastest version on both R & RStudio, but every time that I reboot the PC ad open the program it tells me that some packages are not installed. After several times I have noticed that the problematic packages are: stringi, MASS, survival or Rcpp.
Also if I have to install another package which depends on them a warning appears saying that the packages mentioned are not updated, and it gives me the option to update all.
I tried to reinstall them and enter as an admin in RStudio but nothing works so, does anyone know what is happening here? Thanks for your help.
R packages are installed into libraries. The location of libraries searched by R is determined by the value of .libPaths(). Likely you have the problematic packages installed in more than one library; check for the same package installed in both dir(.libPaths()[1]) and dir(.libPaths()[2]), for instance.
Use remove.packages() with the lib= argument to remove one installation.
My practice is to install R and base packages only in the default library (possibly as administrator), and to install all other packages in a library that I as a regular user have access to. The personal library is the first entry in .libPaths(), which is the default location for package installation. See ?.libPaths for how to set up libraries; all library paths have to exist, else R silently drops them from .libPaths(). I use a setting in ~/.Renviron. Thus
> .libPaths()
[1] "/home/mtmorgan/R/x86_64-pc-linux-gnu-library/3.5-Bioc-3.8" # personal
[2] "/home/mtmorgan/bin/R-3-5-branch/library" # base
> sapply(.libPaths(), function(path) length(dir(path)))
/home/mtmorgan/R/x86_64-pc-linux-gnu-library/3.5-Bioc-3.8
236
/home/mtmorgan/bin/R-3-5-branch/library
30
I want to install package in R : nloptr, seriation, pbkrtest, NbClust, cluster, car, scales, fpc, mclust, apcluster, vegan to use it on my powerbi for k means clustering.
I already install R 3.3.1 in my windows. I open my R like this:
I already tried use two commands to install packages like this:
install.packages("D:/Skripsi/PowerBI-visuals-clustering-kmeans-master.zip', lib='C:/Program Files/R/R-3.3.1',repos = NULL)
install.packages.zip("D:/Skripsi/PowerBI-visuals-clustering-kmeans-master.zip", repos = NULL)
but I get an error
no function install.package.zip or no such file.
my package location : D:\Skripsi\PowerBI-visuals-clustering-kmeans-master
I want to use this package : https://github.com/Microsoft/PowerBI-visuals-clustering-kmeans or do I have to install one by one and how to install package in R? Thank you
If it is a "normal" package:
install.packages("NAME_OF_YOUR_PACKAGE")
It it is a "bioconductor" package:
source("https://bioconductor.org/biocLite.R")
biocLite(NAME_OF_YOUR_PACKAGE)
The repository on GitHub you link to is not in the valid R package structure and thus not installable as such. You are best downloading the files, extracting them locally and sourcing (using function source, see help("source")) any R scripts you may want to use.
As for the rest, there is no function called install.packages.zip that would come with base R installation. When I install packages from local zip files (rarely, though), I use
install.packages("/path/to/zipfile.zip", repos = NULL)
and it appears to work fine. As already said, this won't work for your "PowerBI-visuals-clustering-kmeans-master.zip".
To install the packages you mention, you should do something along the lines of
install.packages(c("nloptr", "seriation", "pbkrtest", "NbClust", "cluster", "car", "scales", "fpc", "mclust", "apcluster", "vegan"))
In R what is the difference between a library and a package?
I have come across posts where people refer to packages within a library. Based on this idea I interpret it that a package lives in a library (i.e I store my packages with a designated library). However I get confused when I want to use package 'x'.
I am under the imperssion I need to call the library function to get package 'x' to be in use ?
And once I have have called upon package 'x' the functions of package 'x' then become available to me ?
In R, a package is a collection of R functions, data and compiled code. The location where the packages are stored is called the library. If there is a particular functionality that you require, you can download the package from the appropriate site and it will be stored in your library. To actually use the package use the command "library(package)" which makes that package available to you. Then just call the appropriate package functions etc.
1. Package
Package extends basic R functionality and standardizes the distribution of code. For example, a package can contain a set of functions relating to a specific topic or tasks.
Packages can be distributed as SOURCE (a directory with all package components), BINARIES (contains files in OS-specific format) or as a BUNDLE (compressed file containing package components, similar to source).
The most basic package, for example created with,
library(devtools)
create("C:/Users/Documents/R-dev/MyPackage")
contains:
R/ directory where all the R code goes to, and DESCRIPTION and NAMESPACE metadata files.
2. Library
Library is a directory where the packages are stored. You can have multiple libraries on your hard drive.
To see which libraries are available (which paths are searched for packages):
.libPaths()
And to see which packages are there:
lapply(.libPaths(), dir)
To use package ‘x’, it first has to be installed in a package library. This can be done for example, with:
install.packages(‘x’) # to install packages from CRAN
or
R CMD INSTALL Xpackagename.tar.gz #to install directly from source
Once installed it has to be loaded into memory with library(x) or require(x).
I am currently trying to run some R code on a computing cluster but cannot run the install.packages function due to some weird firewall settings on my cluster. Since I am only using a few packages in my R code, I was hoping to avoid using the install.packages function by downloading and installing the packages manually.
Note: I am aware that there is a way to avoid this issue by using an HTTP proxy as described in the R FAQ. Unfortunately the people in charge of my cluster are not being helpful in setting this up so I'm forced to consider this alternative approach.
Ideally, I would like to download the packages files from CRAN to my computer, then upload these files to the cluster and install them using the appropriate commands in R. In addition, I would also like to make sure that the packages are installed to a location of my choice since I do not have the permission to "write" in the default R directory (I believe that I can do this within R by using the .libPaths function)
Lastly, the computers that I am working with on the cluster are Unix x86_64.
You can install the package manually using the following command
install.packages('package.zip', lib='destination_directory',repos = NULL)
See the help of ?install.packages, for further description
I also went through the same problem while installing the caret package. There are many dependencies of the caret package.
So, I did the following:
install.packages('caret'):
This gives all packages in zip format the location of download is shown in the error message. Unzip all packages from download source to a location for example in C:/PublicData/RawRPackages, then run following command.
foldername <- 'C:/PublicData/RawRPackages'
install.packages(paste(foldername, 'caret', sep = '/'),
repos = NULL, type = "source")
library(caret, lib.loc = foldername)
this the better way, if we want to download and install locally :
download.packages('lib_name',destdir='dest_path')
for example :
download.packages('RJDBC',destdir='d:/rlibs')
install.packages("libname",lib = "file://F:/test")