How to install package in R - r

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

Related

package 'lubridate' installation error: compilation failed for package 'lubridate' [duplicate]

A friend sent me along this great tutorial on webscraping The New York Times with R. I would really love to try it. However, the first step is to install a package called [RJSONIO][2] from source.
I know R reasonably well, but I have no idea how to install a package from source.
I'm running macOS (OS X).
If you have the file locally, then use install.packages() and set the repos=NULL:
install.packages(path_to_file, repos = NULL, type="source")
Where path_to_file would represent the full path and file name:
On Windows it will look something like this: "C:\\RJSONIO_0.2-3.tar.gz".
On UNIX it will look like this: "/home/blah/RJSONIO_0.2-3.tar.gz".
Download the source package, open Terminal.app, navigate to the directory where you currently have the file, and then execute:
R CMD INSTALL RJSONIO_0.2-3.tar.gz
Do note that this will only succeed when either: a) the package does not need compilation or b) the needed system tools for compilation are present. See: R for Mac OS X
You can install directly from the repository (note the type="source"):
install.packages("RJSONIO", repos = "http://www.omegahat.org/R", type="source")
A supplementarily handy (but trivial) tip for installing older version of packages from source.
First, if you call "install.packages", it always installs the latest package from repo. If you want to install the older version of packages, say for compatibility, you can call install.packages("url_to_source", repo=NULL, type="source"). For example:
install.packages("http://cran.r-project.org/src/contrib/Archive/RNetLogo/RNetLogo_0.9-6.tar.gz", repo=NULL, type="source")
Without manually downloading packages to the local disk and switching to the command line or installing from local disk, I found it is very convenient and simplify the call (one-step).
Plus: you can use this trick with devtools library's dev_mode, in order to manage different versions of packages:
Reference: doc devtools
From CRAN, you can install directly from a GitHub repository address. So if you want the package at https://github.com/twitter/AnomalyDetection, using
library(devtools)
install_github("twitter/AnomalyDetection")
does the trick.
In addition, you can build the binary package using the --binary option.
R CMD build --binary RJSONIO_0.2-3.tar.gz

Install r libraries

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

How to convert R package and dependencies to debian packages?

I need to install R packages in several nodes (10+) in AWS.
I wont be able to open R shell in each and do install.packages("foo")
This will be done using a configuration management tool like Puppet and it'll be easier if i can do an apt-get installation of R packages automatically.
I found a list of R debian packages here:
http://cran.cnr.berkeley.edu/bin/linux/ubuntu/lucid/
But it does not contain all the packages that i need.
Is there a way to convert any R package and it's internal dependencies to a Debian package similar to the approach used in creating r-cran-*.deb?
Have you looked at http://debian-r.debian.net/ ?
All CRAN (and many other) packages already packaged
You can install packages without starting the R console. You can download the tar.gz packages from the cran website. For example here is the tar.gz for the randomForest package: http://cran.r-project.org/src/contrib/randomForest_4.6-7.tar.gz
R CMD INSTALL ${package}.tar.gz
The cran2deb project claims to do exactly this, turning an R package into a Debian package and noting the correct dependencies.
I haven't used it myself yet.

Manually Downloading and Installing Packages in R

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

Only download sources of a package and all dependencies

I am wondering if there's a way to use install.packages() or other related functions to do the following: only download the sources (i.e. tar.gz files) of the specified packages and all their dependencies into a specified folder (on Windows).
One reason to do this is: say I have a Linux account that is not enabled for internet access. In order to install the packages on the Linux machine, I would first download all the needed sources on my Windows machine, then ftp them over to the Linux machine, and install them on the Linux machine using
install.packages('/home/me/R/Packages/blah.tar.gz', repos = NULL)
I recently had a problem where I wanted to download all dependencies and I've solved it thus:
Say I want all the dependencies and imports of ggplot2 and MASS:
getPackages <- function(packs){
packages <- unlist(
tools::package_dependencies(packs, available.packages(),
which=c("Depends", "Imports"), recursive=TRUE)
)
packages <- union(packs, packages)
packages
}
packages <- getPackages(c("ggplot2", "MASS"))
I can now download the packages to another directory.
download.packages(packages, destdir="whereyouactuallywantthefiles",
type="source")
From there if you want to make a local repo on your Linux PC, follow the instructions here.
Try download.packages(c("xts", "rms"), "c:/TEMP", .....) instead of install.packages(); you can directly give it a target directory in the 2nd argument.
Edit several years later: As stated above on other answers and comments, by now several helper functions have been added to R's tools and utils packages. R 3.4.0 will have tools::CRAN_package_db() to download the top-level PACKAGES.rds file (and of course you could just combine download.file() and readRDS() for that too).
There are now better options for this in the tools package that comes with base R: package_dependencies(). See for example, the Answer from #sebastian-c and this recent Q&A for a related use-case.
There is an unexported getDependencies() function in the utils package. I haven't studied how it works, but combining that with #Dirk's Answer should get you most of the way there.
Basically though, it appears you use it like:
utils:::getDependencies(pkgs, dependencies, available, lib)
where pkgs is the character vector of packages to install, dependencies is a character vector of types of dependencies (Depends, Enhances etc) that you want, available is the output from available.packages() and lib is the library location for the packages within which dependencies are evaluated.
If you debug install.packages() it is basically doing the getDependencies() step then #Dirk's download.packages() step before it actually starts installing anything.

Resources