Friday, January 17, 2025
HomeTechR install packages from Shell

R install packages from Shell

To install R packages from the shell (command line), you can follow these steps:

Steps:

  1. Open the shell or terminal.
  2. Use the R command to enter the R environment by typing the following:
    R
    

    This will open the R console in the terminal.

  3. Install R packages using the install.packages() function.
    install.packages("package_name")
    

    For example, to install the ggplot2 package:

    install.packages("ggplot2")
    
  4. Exit the R console by typing:
    q()
    

    Then confirm by typing n or y if asked whether to save the workspace.

Alternatively: Install R Packages Directly from Shell

You can also install R packages directly from the shell without entering the R console by using the Rscript command. Here’s the syntax:

Rscript -e "install.packages('package_name')"

For example, to install ggplot2 directly from the shell, run:

Rscript -e "install.packages('ggplot2')"

Installing Multiple Packages at Once

To install multiple packages at once from the shell, you can pass a vector of package names like this:

Rscript -e "install.packages(c('ggplot2', 'dplyr', 'tidyr'))"

Summary:

  • To enter R and install packages interactively: Use the R command and install.packages().
  • To install packages directly from the shell: Use the Rscript -e command with the install.packages() function.
RELATED ARTICLES
0 0 votes
Article Rating

Leave a Reply

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
- Advertisment -

Most Popular

Recent Comments

0
Would love your thoughts, please comment.x
()
x