R (c): Principle and installation of R package

Source: Internet
Author: User
Tags gz file

A package is a collection of functions, often used as a basic unit of shared code, and packaged in packages to make it easier for other users to use. A growing number of R packages are being created and distributed by different people around the world, and these distributed r packages can be obtained from CRAN or GitHub, and due to the rigorous review of submitting packages to CRAN, some developers do not have the intention to bring their own R package to CRAN, and Devtools can easily Download the installation on GitHub. The life cycle of a package typically goes through five stages of source, bundled, binary, installed, and in-memory. References (http://r-pkgs.had.co.nz/intro.html)

Directory:

    • R Package Basic Content
    • Different forms of R
    • R Package Related commands

R Package Basic content:

    • The content contained in the package contains the following sections in descending order of importance (red denotes the elements that must be included in a package)

      1. r Code (r/): located in the r/folder, place R code files, only the folder of this directory is also a useful package
      2. Package meta-Information (DESCRIPTION): Package description file, the file also generally contains the package's function description, use rights, etc.
      3. Document (man/): Describes how to use the package
      4. Vignettes (vignettes/): A document describing the details of each function in the package, showing how the parts in the package work together to solve specific problems
      5. Test set (tests/): Ensure that packages are designed to work, Testthat packages convert completed interactive tests to formal automated tests
      6. Namespace (Namespace): Defines which functions of the package are available for use by other packages, and what other functions are required for which packages
      7. External Data (data/): The data/directory provides data for packages that can be used conveniently by r users, or to provide compelling examples of documents
      8. Other parts: demo/, exec/, po/and tools/, etc.

different forms of R package: ( reference http://r-pkgs.had.co.nz/package.html)

    • Source Package: development of the source code package, including r/, description, etc.
    • Bundled Package: reduced the source package into a single file (. tar), and use gzip (. gz) to compress the package into a. tar.gz file (the package name suffix that is commonly seen in Linux), which differs from the source package:
      1. Vignettes is compiled into HTML and PDF files.
      2. There are no temporary files in the source package (source package). Files indicated in the Rbuildignore file are excluded from the bundled package)
    • binary Package:binary package can be used by r users without a compiled environment, it is also a single file, but the decompression and source package is very different ( Note: Binary package and platform-related , Mac's package. tgz and Windows. Zip cannot be used universally)
      1. r/folder does not have an R file, but 3 parsed files that are available for efficient invocation. This is the result of the load R code saved with the Save () function
      2. meta/folder contains rd files, which are package-related metadata caches that can be used to view the contents of a file using Readrds (). These files accelerate the load of the package
      3. html/folder contains the files required by HTML Help
      4. src/ The directory becomes the libs/directory, containing the library that compiles the source code
      5. inst/content is moved to the top-level directory
    • Installed package: installed package is to unzip (install) the binary package to a specific library directory, such as showing the different installation methods of the package
    • memory Pack: before using the package, you must load it into memory and use the library () and require () , where the library () function is called, the program aborts and errors if the package does not exist. Call the Requrie () function, and when the package does not exist, a warning is given, and the program continues to execute backwards.
    • Summary:
      1. There are usually two types of R packages that are downloaded from the Web: binary Package and Source pack
      2. Binary package: This is a ready-to-use type (ready-to-use), but depends on the platform, which is different from the win and Linux platforms
      3. Source Package: Such packages can be used across platforms, but need to be processed or compiled prior to use (compiled)
      4. Different suffix names for different platforms, respectively:
    • Linux Environment compilation run: tar.gz file
    • Windows environment compilation run:. zip file
    • MACOSG Environment Compilation run:. tgz file

Package-related commands:

  • install.packages (): online installation of packages posted on Cran when connected to the network. such as: Install.packages ("Ape")
  • Install.packages (Your.zip.files, repos=null): Install the download to local R package
  • . Libpaths (): View the installation directory for the package
  • installed.packages (): View installed package information
  • . Packages (all.available = TRUE): View installed package information
  • Library (mypackage): load MyPackage Pack
  • getOption ("Defaultpackages"): View the packages that are loaded automatically when you start R
  • search (): View the currently loaded package
  • Sessioninfo (): View packages loaded in R
  • Sys.getenv ("R_home"): Query R HOME installation Address
  • Sys.getenv ("Home"): Query user Home Address
  • remove.packages ("MyPackage"): Uninstall Package
  • Detach ("Package:demo"): deletes the loaded package in the current session memory
  • Update.packages (): Update package

GitHub Package Installation:

    • Dependent devtools tool, installation command: install.packages ("Devtools")
    • The Devtools package's Install_github () function is used to download and install the R package locally from GitHub, and the sample code is installed as follows:
      Library (Devtools) install_github (' Badbye/baidumap ')
    • The example finds that the parameters required for the install.packages () and Install_github () functions are different. Install.packages () requires only the package name, and Install_github () needs to provide a repository name for GitHub. This means that when you want to install an R package from GitHub, you have to remember exactly what the warehouse name is, and it's annoying that we often have a hard time remembering GitHub's username

    • The Githubinstall package provides a way similar to Install.packages (), which simply installs the R package from GitHub with the package name, has been published to Cran, and the installation commands are as follows:
      Install.packages ("Githubinstall")
    • When you install the package on GitHub again, the sample code is as follows:

      Library (Githubinstall) githubinstall ("Baidumap")

R (c): Principle and installation of R package

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.