In this lesson we learn about a few insider tips which hopefully will facilitate learning R.

18. Notes on RStudio

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).

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:

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.

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.

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

19. 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)
  1. Great R packages for data import, wrangling & visualization

  2. R packages I wish I knew about earlier

  3. Quick list of useful R packages