12 Useful tips
In this lesson we learn about a few insider tips which hopefully will facilitate learning R.
12.1 Useful tips for RStudio
12.1.1 Using auto-complete in RStudio.
In many circumstances you can press Tab to let RStudio provide a suggestion as to what you mean. For example, type the first part of the name of a variable or function, and by pressing Tab will list the options available (or even outright complete the name if there is just one option).
12.1.2 Project management in RStudio
Using projects in RStudio is a powerful means of working on several projects at the same time. Each of the projects has its own:
12.1.3 Version control repository
Version control is an important tool in tracking the progression of your software. In RStudio, we will be using git to version control our code. A git repository is associated with an RStudio project, so each project has its own git repository.
12.1.4 RStudio projects
I recommend creating a RStudio project for each of the tutorials you will be doing. This makes it easy to separate the code between the tutorials, and will make it easy for you to find back what you wrote regarding a particular tutorial.
12.1.4.1 Create a new RStudio project
- Select File > New project.
- Select New Directory.
- Select Empty project.
- Select a name and sub directory of your project.
Create another RStudio project, and try switching between them. Create a number of R scripts as a part of the project. Mind to save them and name them. And you can switch back and forth.
If you are interested in knowing more features of RStudio, visit this link
12.2 R packages: Personal recommendations for beginers
Below you find a function to batch the process of installation of ‘selected’ R packages in your machine. Here the a link to the below R Packages descriptions
libs=c(
# General
"devtools", "foreign", "car", "mvtnorm", "MASS",
# Linear (Mixed) Models
"nlme","lme4", "lmerTest", "glmnet", "lmtest", "multcomp",
# To report results
"knitr", "markdown", "formatR", "shiny", "rmarkdown", "rmdformats",
# R commander
"Rcmdr",
# Psychology Methods
"psych", "Hmisc", "sem", "scales",
# Data manipulation
"reshape2", "plyr", "dplyr", "tidyr", "stringr", "lubridate",
"xtable", "manipulate",
# Visualize & Graphing data
"ggplot2", "lattice", "colorspace", "RColorBrewer", "gplots",
"mosaic", "vcd","ggvis", "latticeExtra",
# Time Series
"timeSeries", "timeDate", "tseries", "xts", "zoo"# time series
)
type=getOption("pkgType")
CheckInstallPackage <- function(packages, repos="http://cran.r-project.org",
depend=c("Depends", "Imports"), ...) {
installed=as.data.frame(installed.packages())
for(p in packages) {
if(is.na(charmatch(p, installed[,1]))) {
install.packages(p, repos=repos, dependencies=depend, ...)
}
}
}
CheckInstallPackage(packages=libs)
12.2.1 Other selections of “best” R packages [links]
12.3 20. Useful Resources [links]
Beginners’ guides to R & RStudio
R Style Guides
R Markdown Cheat Sheets [links]