R Commands Cheat Sheet



Base R Graphics Cheat Sheet David Gerard August 8, 2017. Abstract: I reproduce some of the plots from Rstudio’s ggplot2 cheat sheet using Base R graphics. Think of cheat sheets as a quick reference, with the emphasis on quick. Here's an analogy: A cheat sheet is more like a well-organized computer menu bar that leads you to a command than like a manual that documents each command. Everything about your cheat sheet should be designed to lead users to essential information quickly. R Reference Card by Tom Short, EPRI PEAC, tshort@epri-peac.com 2004-11-07 Granted to the public domain. See www.Rpad.org for the source and latest. Essential Statistics with R: Cheat Sheet Important libraries to load If you don’t have a particular package installed already: install.packages(Tmisc). Basic Linux commands. Description ls Lists all files and directories in the present working directory.

Documentation#

TopicLink
Generalhttps://docs.rstudio.com/
Installing Rhttps://docs.rstudio.com/resources/install-r/
Installing Pythonhttps://docs.rstudio.com/resources/install-python/
RStudio Server admin guidehttps://docs.rstudio.com/ide/server-pro/
RStudio Connect admin guidehttps://docs.rstudio.com/connect/admin/
RStudio Package Manager admin guidehttps://docs.rstudio.com/rspm/admin/
Pro Drivershttps://docs.rstudio.com/pro-drivers/

Pre-requisites:

Installing R#

Install R from pre-compiled binaries#

Recommended best practise is to install R from pre-compiled binaries

For example, on Ubuntu 18.04 for R version 3.6.1.

This script installs into /opt/R/...

Verify installation:

RStudio Server Pro#

Admin guide: https://docs.rstudio.com/ide/server-pro/

Starting, stopping and restarting#

Running the verify installation command:

To restart the RSP service and check its status, run these commands (with sudo if necessary):

Status#

Error logs#

The locations of the various server log files:

The server log is at:

RStudio Connect#

Admin guide: https://docs.rstudio.com/connect/admin/

Config file#

Systemd vs upstart#

Distributions using systemd include Red Hat/CentOS 7, Red Hat/CentOS 8, SUSE 12, Ubuntu 16.04, and Ubuntu 18.04.

  • systemctl start rstudio-connect

Distributions using Upstart include Red Hat/CentOS 6 and Ubuntu 14.04.

  • start rstudio-connect

Starting and stopping#

Checking status#

Log files#

Get the diagnostics script#

RStudio Package Manager#

Admin guide: https://docs.rstudio.com/rspm/admin/

The rspm command#

Try running the rspm command on the server instance where RSPM is installed:

To save keystrokes when typing RSPM commands, create a command alias for therspm command:

Run the rspm command with no arguments for a list of available commands:

Working with CRAN#

Manage repositories and sources#

Manage packages#

Working with repositories#

Utilities#

System health check#

You have various methods to check the health of your RSPM instance:

  1. View the RSPM application logs:

  2. View the RSPM access logs:

  3. Check the status of your RSPM license:

  4. Run RSPM diagnostics:

  5. View diagnostics output:

License manager#

View license status#

Activate license:

List of available commands:

Supported commands:

Expired license#

Things to try:

Cheat
  • Check time and time zone timedatectl
  • Resync if needed, e.g. sudo hwclock -w
  • Restart

Deactivating a license#

Deactivation tool: http://apps.rstudio.com/deactivate-license/

Pro Drivers#

Documentation overview: https://docs.rstudio.com/pro-drivers/

Driver locations:

Troubleshooting#

Troubleshooting R#

Almost all RStudio products depend on R being installed successfully to run.

  • Look for errors related to R in the server logs

Can R be launched manually and can the user's code be run in R without any errors?

How was R installed?

  • From source or pre-compiled binaries? If so, were all correct flags and capabilities set?

Are all necessary dependencies installed?

Are the permissions set correctly to allow r-x by all?

Are there multiple versions of R on the system?

Troubleshooting configuration#

Look for any errors in the startup. You can view the live log during startup using:

Read through the admin guides and make sure you have the correct formatting

Make sure you're on the right version of the product compared to the admin guide!

Troubleshooting authentication#

It is difficult for RStudio Support to troubleshoot as it depends on external configuration values unknown to us.

Does it work outside of the RStudio product?

  • Often possible to copy over working setup from other systems or services.
  • For RStudio Server Pro, thepamtester utility lets you test outside RStudio systems.

Check server log files including access.log files.

Check connections to any external authentication providers

  • Kerberos, Active Directory, etc.

General Linux tips#

Operating system version#

What OS are you using?

or

Export environment variable to PATH#

R Commands Cheat Sheet

Persist changes on startup in .bashrc#

You can run scripts and define variables on startup by adding lines to your .bashrc file:

This article lists down 10 popular machine learning algorithms and related R commands (& package information) that could be used to create respective models. The objective is to represent a quick reference page for beginners/intermediate level R programmers who working on machine learning related problems. Please feel free to comment/suggest if I missed to mention one or more important points. Also, sorry for the typos.
Following are the different ML algorithms included in this article:
  1. Linear regression
  2. Logistic Regression
  3. K-Means Clustering
  4. K-Nearest Neighbors (KNN) Classification
  5. Naive Bayes Classification
  6. Decison Trees
  7. Support Vector Machine (SVM)
  8. Artifical Neural Network (ANN)
  9. Apriori
  10. AdaBoost


Cheat Sheet – ML Algorithms & R Commands
  • Linear regression: “lm” method from base package could be used for linear regression models. Following is the sample command:
  • Logistic Regression: Logistic regression is a classification based model. “glm” method from base R package could be used for logistic regression. Following is the sample command:
  • K-Means Clustering: “kmeans” method from base R package could be used to run k-means clustering. Following is a sample command given X is a data matrix and m is the number of clusters:
  • K-Nearest Neighbors (KNN) Classification: “knn” method from “class” package could be used for K-NN modeling. One need to install and load “class” package. Following is the sample command given X_train represents a training dataset, X_test represents test data set, k represents number of nearest neighbors to be included for the modeling
  • Naive Bayes Classification: “naiveBayes” method from “e1071” package could be used for Naive Bayes classification. One need to install and load “e1071” package prior to analysis. Following is the sample command:
  • Decision Trees: “rpart” method from “rpart” can be used for Decision Trees. One need to install and load “rpart” package. Following is the sample command:
  • Support Vector Machine (SVM): “svm” method from “e1071” package could be used for SVM. Note that the same package also provide method, naiveBayes, for Naive Bayes classification. One need to install and load “e1071” package. Following is the sample command given X is the matrix of features, labels be the vector of 0-1 class labels, and C being regularization parameter
  • Artifical Neural Network (ANN): “neuralnet” method from “neuralnet” package could be used for ANN modeling. Following is sample command:

    Prediction could be made using following formula:

  • Apriori: “apriori” method from “arules” package could be used for Apriori analysis. One need to install and load “arules” package. Following is the sample command:
  • AdaBoost: “ada” method from “rpart” package could be used as boosting function. Following is sample command:

For most of the above formulas including linear regression model, one could use following function to predict:


Cheat Sheet For R

  • First Principles Understanding based on Physics - April 13, 2021
  • Precision & Recall Explained using Covid-19 Example - April 11, 2021
  • Moving Average Method for Time-series forecasting - April 4, 2021