Install R Packages and Load Libraries

R is an interpreter instead of compiled language.  Installing R Packages and loading R libraries are required first steps since R software only comes with base R installed. Only minimum R tasks can be performed with base R. R Studio is a powerful user interface to access objects and data frames.

  • # Two options to install R packages

  • install.packages("gtsummary") # install from CRAN through RStudio
    remotes::install_github("ddsjoberg/gtsummary") # install directly from github, ideal to install older versions
  • # Install R package if not already installed - This method works for Test R site
  • if(!require('data.table')) {

  • install.packages('data.table')
  • library('data.table')
  • }
  • source(file = 'C:/my_Rproject/startup.R') # load packages instead of in each R script 

  • # instead of having code below in each R script, save it in startup.R and insert source() in each R script

  • install.packages('tidyverse')
  • library(tidyverse) # load popular data management package
  • library(dplyr) # load common data management and sql package
  • install.packages("ggplot2") # Install & load ggplot2 package

  • library("ggplot2")
  • library() # display loaded libraries
  • .libPaths() # display path of each package
    • lsf.str("package:dplyr") # display dplyr functions
    • lsf.str("package:tidyverse") # display tidyverse functions

    Base R Packages

    Install R Packages and Load Libraries Exercises (Next Section)

    1. Install Tidyverse
    2. Load Tidyverse and dplyr packages 


    How to import data and install packages [You Tube]

    R Studio Server Setup: Virtual Private Server [You Tube]


    How do I select an R package for my clinical workflow? Sean Lopp & Phil Bowsher [Common FAQs]

    Installing Base-R and RStudio [YaRrr!]

    R Studio Cloud Setup - New AccountBlog, Videos, Guide, Verify, Project Template

    GitHub Validation Scripts: R-IQ-OQ, R-IQ-OQ-PQ, Test Plan [Installation Qualification, Operational Qualification, Performance Qualification, Book]

    SAS® 9.4 Installation Qualification Guide [Reference]

    Setting up the R environment

    R Packages: A Beginner's Tutorial

    Difference between R-base and R-recommended packages

    Unable to load packages after updating R to 4.3 [Posit Blog]

    Use pak package to install R packages

    • pak::pak("tidyverse/ggplot2") # local directory backup

    Load Packages Automatically in RStudio

    > file.edit("~/Desktop/foo/.Rprofile") # This opens up a script window, within which you can enter in your library commands library(ggplot2) library(scales) library(plyr) library(reshape2)

    An efficient way to install and load R packages

    • install.packages("librarian")
    • librarian::shelf(ggplot2, DesiQuintans / desiderata, pander)

    How to load packages in R automatically

    Powered by Wild Apricot Membership Software