4 installation methods of R package
R language pack related commands
R install.packages() set domestic CRAN image
Tsinghua University open source software image station
R language - default mirror settings
R package installation and setting image
It's very difficult for novices to learn R language. As my colleagues said, R knowledge seems scattered. It's my fault that I haven't learned the introductory book of R language well. It's hard at the beginning. Just stick to it.
In the RNA SEQ process, the. count file should be processed in the early stage of data processing. At present, there are three known software that can be used: DESeq2, edgeR and balldown. All three software seem to be r-packages? You need to install r first, and then download the corresponding R package.
In the previous article, R was installed. Because the server disconnected the foreign website, the software could not be installed in the default way of R. In the past two days, I tried to set the image of R as the internal source of the country, and finally succeeded, so I quickly recorded it.
Refer to the relevant commands on the network, and use the [? conmand()] mode to view the relevant command descriptions. The WSL subsystem operation in your windows10 system is recorded as follows.
1. Check the installation location of R package
# instructions Search Paths for Packages Description: '.libPaths' gets/sets the library trees within which packages are looked for. Usage: .libPaths(new) .Library .Library.site # Operation record >.libPaths()  "/home/zexing/miniconda3/envs/R4.0/lib/R/library"
2. Install the specified package
# instructions Install Packages from Repositories or Local Files Description: Download and install packages from CRAN-like repositories or from local files. Usage: install.packages(pkgs, lib, repos = getOption("repos"), contriburl = contrib.url(repos, type), method, available = NULL, destdir = NULL, dependencies = NA, type = getOption("pkgType"), configure.args = getOption("configure.args"),configure.vars =getOption("configure.vars"), clean = FALSE, Ncpus = getOption("Ncpus", 1L), verbose = getOption("verbose"), libs_only = FALSE, INSTALL_opts, quiet = FALSE,keep_outputs = FALSE, ...)
- Networking default installation
# Call command to install directly > install.packages("BiocManager") --- Please select a CRAN mirror for use in this session --- Secure CRAN mirrors 1: 0-Cloud [https] 2: Australia (Canberra) [https] 3: Australia (Melbourne 1) [https] 4: Australia (Melbourne 2) [https] 5: Australia (Perth) [https] # Omit.... # You need to further adjust the default Tsinghua image source, instead of selecting different image sources every time. trying URL 'https://mirrors.tuna.tsinghua.edu.cn/CRAN/src/contrib/BiocManager_1.30.10.tar.gz' Content type 'application/x-gzip' length 40205 bytes (39 KB) ================================================== downloaded 39 KB * installing *source* package 'BiocManager' ... ** package 'BiocManager' successfully unpacked and MD5 sums checked ** using staged installation ** R ** inst ** byte-compile and prepare package for lazy loading ** help *** installing help indices ** building package indices ** installing vignettes ** testing if installed package can be loaded from temporary location ** testing if installed package can be loaded from final location ** testing if installed package keeps a record of temporary installation path * DONE (BiocManager) The downloaded source packages are in '/tmp/RtmpUM5d8d/downloaded_packages' Updating HTML index of packages in '.Library' Making 'packages.html' ... done
- Network specific image source installation
# install.packages("name", repos='URL ') > install.packages("ggplot2", repos='https://mirrors.tuna.tsinghua.edu.cn/CRAN') also installing the dependencies 'ps', 'processx', 'callr', 'prettyunits', 'backports', 'desc', 'pkgbuild', 'rprojroot', 'rstudioapi', 'evaluate', 'pkgload', 'praise', 'colorspace', 'assertthat', 'utf8', 'Rcpp', 'testthat', 'farver', 'labeling', 'lifecycle', 'munsell', 'R6', 'RColorBrewer', 'viridisLite', 'cli', 'crayon', 'ellipsis', 'fansi', 'magrittr', 'pillar', 'pkgconfig', 'vctrs', 'digest', 'glue', 'gtable', 'isoband', 'rlang', 'scales', 'tibble', 'withr' trying URL 'https://mirrors.tuna.tsinghua.edu.cn/CRAN/src/contrib/ps_1.3.3.tar.gz' Content type 'application/octet-stream' length 98973 bytes (96 KB) ================================================== # Omit...
- Install using local source package
# Download the required Source package from the official website of Bioconductor to the specified directory > install.packages("/home/zexing/R_lib/Biobase_2.48.0.tar.gz", repos = NULL, type = "source") * installing *source* package 'Biobase' ... ** using staged installation ** libs #Omit...
3. View installed packages
# instructions Find Installed Packages Description: Find (or retrieve) details of all packages installed in the specified libraries. Usage: installed.packages(lib.loc = NULL, priority = NULL, noCache = FALSE, fields = NULL, subarch = .Platform$r_arch, ...) # Operation record >installed.packages() Package LibPath base "base" "/home/zexing/miniconda3/envs/R4.0/lib/R/library" boot "boot" "/home/zexing/miniconda3/envs/R4.0/lib/R/library" class "class" "/home/zexing/miniconda3/envs/R4.0/lib/R/library" cluster "cluster" "/home/zexing/miniconda3/envs/R4.0/lib/R/library" codetools "codetools" "/home/zexing/miniconda3/envs/R4.0/lib/R/library" compiler "compiler" "/home/zexing/miniconda3/envs/R4.0/lib/R/library" datasets "datasets" "/home/zexing/miniconda3/envs/R4.0/lib/R/library" foreign "foreign" "/home/zexing/miniconda3/envs/R4.0/lib/R/library" graphics "graphics" "/home/zexing/miniconda3/envs/R4.0/lib/R/library" grDevices "grDevices" "/home/zexing/miniconda3/envs/R4.0/lib/R/library" grid "grid" "/home/zexing/miniconda3/envs/R4.0/lib/R/library" KernSmooth "KernSmooth" "/home/zexing/miniconda3/envs/R4.0/lib/R/library" lattice "lattice" "/home/zexing/miniconda3/envs/R4.0/lib/R/library" MASS "MASS" "/home/zexing/miniconda3/envs/R4.0/lib/R/library" Matrix "Matrix" "/home/zexing/miniconda3/envs/R4.0/lib/R/library" methods "methods" "/home/zexing/miniconda3/envs/R4.0/lib/R/library" mgcv "mgcv" "/home/zexing/miniconda3/envs/R4.0/lib/R/library" nlme "nlme" "/home/zexing/miniconda3/envs/R4.0/lib/R/library" nnet "nnet" "/home/zexing/miniconda3/envs/R4.0/lib/R/library" parallel "parallel" "/home/zexing/miniconda3/envs/R4.0/lib/R/library" rpart "rpart" "/home/zexing/miniconda3/envs/R4.0/lib/R/library" spatial "spatial" "/home/zexing/miniconda3/envs/R4.0/lib/R/library" splines "splines" "/home/zexing/miniconda3/envs/R4.0/lib/R/library" stats "stats" "/home/zexing/miniconda3/envs/R4.0/lib/R/library" stats4 "stats4" "/home/zexing/miniconda3/envs/R4.0/lib/R/library" survival "survival" "/home/zexing/miniconda3/envs/R4.0/lib/R/library" tcltk "tcltk" "/home/zexing/miniconda3/envs/R4.0/lib/R/library" tools "tools" "/home/zexing/miniconda3/envs/R4.0/lib/R/library" utils "utils" "/home/zexing/miniconda3/envs/R4.0/lib/R/library"
4. View package information
# instructions Package Description Description: Parses and returns the 'DESCRIPTION' file of a package as a '"packageDescription"'. Utility functions return (transformed) parts of that. Usage: packageDescription(pkg, lib.loc = NULL, fields = NULL, drop = TRUE, encoding = "") packageVersion(pkg, lib.loc = NULL) packageDate(pkg, lib.loc = NULL, date.fields = c("Date", "Packaged", "Date/Publication", "Built"), tryFormats = c("%Y-%m-%d", "%Y/%m/%d", "%D", "%m/%d/%y"), desc = packageDescription(pkg, lib.loc=lib.loc, fields=date.fields)) asDateBuilt(built) # Operation record > packageDescription("utils") Package: utils Version: 3.6.3 Priority: base Title: The R Utils Package Author: R Core Team and contributors worldwide Maintainer: R Core Team <Rfirstname.lastname@example.org> Description: R utility functions. License: Part of R 3.6.3 Suggests: methods, xml2, commonmark NeedsCompilation: yes Built: R 3.6.3; x86_64-conda_cos6-linux-gnu; 2020-004-29 00:10:12 UTC; unix -- File: /home/zexing/miniconda3/envs/R3.6.3/lib/R/library/utils/Meta/package.rds > packageVersion("utils")  '3.6.3' > packageDate("utils") "2020-04-29"
5. Update package
# instructions Compare Installed Packages with CRAN-like Repositories Description: 'old.packages' indicates packages which have a (suitable) later version on the repositories whereas 'update.packages' offers to download and install such packages. 'new.packages' looks for (suitable) packages on the repositories that are not already installed, and optionally offers them for installation. Usage: update.packages(lib.loc = NULL, repos = getOption("repos"), contriburl = contrib.url(repos, type), method, instlib = NULL, ask = TRUE, available = NULL, oldPkgs = NULL, ..., checkBuilt = FALSE, type = getOption("pkgType")) old.packages(lib.loc = NULL, repos = getOption("repos"), contriburl = contrib.url(repos, type), instPkgs = installed.packages(lib.loc = lib.loc, ...), method, available = NULL, checkBuilt = FALSE, ..., type = getOption("pkgType")) new.packages(lib.loc = NULL, repos = getOption("repos"), contriburl = contrib.url(repos, type), instPkgs = installed.packages(lib.loc = lib.loc, ...), method, available = NULL, ask = FALSE, ..., type = getOption("pkgType")) # Operation record >update.packages("utils") --- Please select a CRAN mirror for use in this session --- Secure CRAN mirrors 1: 0-Cloud [https] 2: Australia (Canberra) [https] 3: Australia (Melbourne 1) [https] 4: Australia (Melbourne 2) [https] 5: Australia (Perth) [https] # Omit.... # In this step, you need to connect to the Internet to display. My server can't connect to the Internet and can't come out of these options. # You need to further adjust the default Tsinghua image source, instead of selecting different image sources every time.
6. Load package
# instructions Loading/Attaching and Listing of Packages Description: 'library' and 'require' load and attach add-on packages. Usage: library(package, help, pos = 2, lib.loc = NULL, character.only = FALSE, logical.return = FALSE, warn.conflicts, quietly = FALSE, verbose = getOption("verbose"), mask.ok, exclude, include.only, attach.required = missing(include.only)) require(package, lib.loc = NULL, quietly = FALSE, warn.conflicts, character.only = FALSE, mask.ok, exclude, include.only, attach.required = missing(include.only)) conflictRules(pkg, mask.ok = NULL, exclude = NULL) # Operation record >library("BiocManager") Bioconductor version 3.11 (BiocManager 1.30.10), ?BiocManager::install for help > # After loading the package, display the version information and help of the package, and then enter the > prompt to wait for further commands >require("package_name")
7. View the loaded package
# instructions Listing of Packages Description: '.packages' returns information about package availability. Usage: .packages(all.available = FALSE, lib.loc = NULL) # Operation record >.packages()
8. Remove the loaded package (remove the package from the R running environment)
# instructions Detach Objects from the Search Path Description: Detach a database, i.e., remove it from the 'search()' path of available R objects. Usually this is either a 'data.frame' which has been 'attach'ed or a package which was attached by 'library'. Usage: detach(name, pos = 2L, unload = FALSE, character.only = FALSE, force = FALSE) #Operation record >detach("BiocManager")
9. Completely remove the installed package
>remove.packages("package_name", lib = file.path("path/to/library"))
Because the server is disconnected from foreign websites, after installing Miniconda3, it is set as Tsinghua image source. You can install R software through Miniconda3. However, the use of R software requires some R packages, external network or corresponding image source. In the help description provided by Tsinghua image source, there is a description of the image source of R (CRAN):
CRAN image help One of CRAN (The Comprehensive R Archive Network) image source configuration files is. Rprofile (located in ~ /. Rprofile under Linux). Add the following statement at the end of the article: options("repos" = c(CRAN="https://mirrors.tuna.tsinghua.edu.cn/CRAN/")) Open r to install the R package using the CRAN image source.
The file ~ /. Rprofile was never found on the server. Online reference articles are all aimed at setting up Tsinghua image source in a way that can be connected to the Internet or with root permission. I can't do either of these two things. Fortunately, one article article It provides a method to call the image from the command line. The rookie quickly records it.
# Setting up image source of Tsinghua University > options(repos=structure(c(CRAN="https://mirrors.tuna.tsinghua.edu.cn/CRAN/"))) # Setting up image source of Tongji University > options(repos=structure(c(CRAN="https://mirrors.tongji.edu.cn/CRAN/")))
This mode needs to be executed once every time R is turned off and restarted.
1. Several operations on image
# View the current image address > getOption("repos") CRAN "@CRAN@" # View R_HOME address > R.home()  "/home/zexing/miniconda3/envs/R3.6.3/lib/R" # View the first element of the repos option to get the URL address of the selected image > options("repos")[] CRAN "@CRAN@" # Call the chooseCRANmirror function to select a mirror > chooseCRANmirror() Secure CRAN mirrors 1: 0-Cloud [https] 2: Australia (Canberra) [https] 3: Australia (Melbourne 1) [https] # Omit....
2. Temporarily set the image source
- Call the chooseCRANmirror function to select a mirror
> chooseCRANmirror() Secure CRAN mirrors 1: 0-Cloud [https] 2: Australia (Canberra) [https] 3: Australia (Melbourne 1) [https] # Omit....
- Command line execution
> options(repos=structure(c(CRAN="https://mirrors.tuna.tsinghua.edu.cn/CRAN/"))) # Setting up image source of Tsinghua University > options(repos=structure(c(CRAN="https://mirrors.tongji.edu.cn/CRAN/"))) # Setting up image source of Tongji University
3. Set image source permanently
Read so many on the Internet, there is no success for the time being. Let it be solved later.