1. Linux
-
Note: Do not install on a headless machine because R and RStudio require a graphical user interface.
1.1. Installation
-
Enter the following commands at a Command Line.
sudo apt-get install r-base R --version
1.2. Usage
-
Start Applications > Graphics > R.
-
Enter the following commands.
pkgbuild::check_build_tools(debug = TRUE) pkgbuild::check_compiler(debug = TRUE) -
Close R.
2. Windows
2.1. Installation
-
Note: Remove any previous version.
-
Run the R-4.4.0-win.exe file with administrative privileges.
-
Select English.
-
Click OK.
-
Click Next.
C:\Program Files\R\R-4.4.0
-
Click Next.
-
Select User installation.
■ Main Files ■ 64-bit Files ■ Message translations
-
Click Next.
-
Choose No (accept default) to skip customizing the startup options.
○ Yes (customized startup) ● No (accept defaults)
-
Click Next.
-
Uncheck Don’t create a Start Menu folder.
-
Click Next.
-
Uncheck Create a desktop shortcut.
□ Create a desktop shortcut □ Create a Quick Launch shortcut ■ Save version number in registry ■ Associate R with .RData files
-
Click Next.
-
Click Finish.
2.2. Configuration
-
Note: To be able to use R in the Command Prompt, the installation directory needs to be added to the PATH system environment variable.
-
Open Control Panel > System.
-
Select Advanced system settings.
-
Select the Advanced tab.
-
Click Environment Variables.
-
Select System variables > Path.
-
Click Edit.
-
Click New.
-
Type
C:\Program Files\R\R-4.4.0\bin\x64. -
Click OK.
-
Click OK.
-
Click OK.
-
Close System.
-
Append the follwoing lines to the C:\Program Files\R\R-4.4.0\etc\Rprofile.site file.
# Set maximum number of columns on a line (only needed for R-CLI). # Note: In R-CLI Sys.getenv("COLUMNS") returns a valid number. # In R-GUI Sys.getenv("COLUMNS") returns an empty string. if (Sys.getenv("COLUMNS") != "") { options(width=Sys.getenv("COLUMNS")) options(setWidthOnResize=TRUE) } as.integer(sub("^.* ", "", grep(value=TRUE, "Columns:", shell("mode con", intern=TRUE)))) columns <- as.integer(sub("^.* ", "", grep(value=TRUE, "Columns:", shell("mode con", intern=TRUE)))) print(columns) # Set CRAN mirror to "East Asia [https]". options(repos = c(CRAN = "https://cran.asia/"))
2.3. Usage
-
Start R from the Start menu.
-
Enter the following commands at the R Prompt.
# Show directory in which R is installed (R_HOME). R.home() # [1] "C:/PROGRA~1/R/R-44~1.0" normalizePath(R.home()) # "C:\\Program Files\\R\\R-4.4.0" normalizePath(Sys.getenv("R_HOME")) # [1] "C:\\Program Files\\R\\R-4.4.0" Sys.getenv("R_HOME") # [1] "C:/PROGRA~1/R/R-44~1.0" # Show user's home directory (HOME). path.expand("~") # [1] "C:\\Users\\Administrator\\Documents" / "C:\\Users\\Douwe\\Documents" Sys.getenv("HOME") # [1] "C:\\Users\\Administrator\\Documents" / "C:\\Users\\Douwe\\Documents" # Show current working directory. getwd() # [1] "C:/Users/Administrator" / "C:/Users/Douwe/Documents" # Show the maximum number of columns on a line. getOption("width") # [1] 192 / 237 # Show CRAN mirror. getOption("repos") # CRAN = "https://cran.asia/" # Show installed packages. ip <- as.data.frame(installed.packages()[,c(1,3:4)]) rownames(ip) <- NULL ip <- ip[is.na(ip$Priority),1:2,drop=FALSE] print(ip, row.names=FALSE) # Quit. q(save = "no")