- Basic R Commands Cheat Sheet
- R Common Commands Cheat Sheet
- R Commands Cheat Sheet
- R Program Cheat Sheet
- Cheat Sheet For R
- R Studio Commands Cheat Sheet
- R Cheat Sheets Pdf
- R Markdown Cheatsheet R Markdown is an authoring format that makes it easy to write reusable reports with R. You combine your R code with narration written in markdown (an easy-to-write plain text format) and then export the results as an html, pdf, or Word file. You can even use R Markdown to build interactive documents and slideshows.
- Start profiling R code: stopBuild: Stop the current build: stopProfiler: Stop profiling R code: suspendSession: Suspend R Session: switchToChunkBash: Switch chunk to Bash: switchToChunkPython: Switch chunk to Python: switchToChunkR: Switch chunk to R: switchToChunkRCPP: Switch chunk to Rcpp: switchToChunkSQL: Switch chunk to SQL: switchToChunkStan: Switch chunk to Stan.
- Linear regression
- Logistic Regression
- K-Means Clustering
- K-Nearest Neighbors (KNN) Classification
- Naive Bayes Classification
- Decison Trees
- Support Vector Machine (SVM)
- Artifical Neural Network (ANN)
- Apriori
- AdaBoost
Basic Linux commands. Description ls Lists all files and directories in the present working directory. Essential Statistics with R: Cheat Sheet Important libraries to load If you don’t have a particular package installed already: install.packages(Tmisc). Work with strings with stringr:: CHEAT SHEET Detect Matches strdetect(string, pattern) Detect the presence of a pattern match in a string. Strdetect(fruit, 'a') strwhich(string, pattern) Find the indexes of strings that contain a pattern match. Strwhich(fruit, 'a') strcount(string, pattern) Count the number of matches in a string.
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:
- 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
Documentation#
Topic | Link |
---|---|
General | https://docs.rstudio.com/ |
Installing R | https://docs.rstudio.com/resources/install-r/ |
Installing Python | https://docs.rstudio.com/resources/install-python/ |
RStudio Server admin guide | https://docs.rstudio.com/ide/server-pro/ |
RStudio Connect admin guide | https://docs.rstudio.com/connect/admin/ |
RStudio Package Manager admin guide | https://docs.rstudio.com/rspm/admin/ |
Pro Drivers | https://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#
Basic R Commands Cheat Sheet
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#
R Common Commands Cheat Sheet
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:
R Commands Cheat Sheet
View the RSPM application logs:
View the RSPM access logs:
Check the status of your RSPM license:
Run RSPM diagnostics:
View diagnostics output:
License manager#
View license status#
Activate license:
List of available commands:
Supported commands:
Expired license#
Things to try:
- 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, the
pamtester
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
R Program Cheat Sheet
Export environment variable to PATH#
Cheat Sheet For R
R Studio Commands Cheat Sheet
Persist changes on startup in .bashrc#
R Cheat Sheets Pdf
You can run scripts and define variables on startup by adding lines to your .bashrc
file: