R session = environment + packages

R For SAS Users

Melinda Higgins, PhD

Research Professor/Senior Biostatistician Emory University

Why learn R?

  • R logo
  • R is FREE. Free as in no cost and free as in open source licensing
  • R's popularity is growing rapidly $^1$
    • Data science jobs for R have now surpassed those for SAS
    • R appears to now be more commonly reported in scholarly articles than SAS
  • The basic R installation is small (usually <100MB)
  • Did I mention R is FREE?
1 [https://r4stats.com/articles/popularity/](https://r4stats.com/articles/popularity/)
R For SAS Users

A computing session SAS vs R

sas components

R For SAS Users

A computing session SAS vs R

add sas work library

R For SAS Users

A computing session SAS vs R

r packages

R For SAS Users

A computing session SAS vs R

add r global environment

R For SAS Users

A computing session SAS vs R

arrow link between sas components and r packages

R For SAS Users

A computing session SAS vs R

arrow link between sas work library and r global environment

R For SAS Users

Data and other objects

sas proc datasets like r ls list function

 

  • ls() lists all data and related objects loaded in R session's global environment
R For SAS Users

Load data files

sas libname or data and set statement like r load function

 

  • load() loads datasets in .RData binary format
R For SAS Users

Global environment - new session

Usually there are no objects in the global environment at the beginning of a new R session.

ls()
character(0)
R For SAS Users

Load data

  • Abalone dataset $^1$
  • Shellfish similar to clams, mussels or oysters
  • Marine Research Lab, Tasmania, Australia
  • Use measurements to predict age
# Load the abalone dataset
load("abalone.RData")

# List the objects in memory
ls()
"abalone"

picture of abalone

1 [https://archive.ics.uci.edu/ml/datasets/abalone](https://archive.ics.uci.edu/ml/datasets/abalone)
R For SAS Users

Getting help

sas help menu like r help function

 

  • help() provides access to documentation for any function or package installed
R For SAS Users
help(ls)

screenshot of r ls list function help page

R For SAS Users

Settings and functionality

sas proc setinit and product status procedures like r sessioninfo and library functions

  • sessioninfo() provides details on computer system and packages loaded
  • library() is used to load packages during your R session
  • Tens of thousands of R packages are available and increasing everyday $^1$
1 [https://cran.r-project.org/web/packages/](https://cran.r-project.org/web/packages/)
R For SAS Users

R sessionInfo

sessionInfo()
R version 3.4.3 (2017-11-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     
R For SAS Users

R sessionInfo

# Load the dplyr package and run sessionInfo again
library(dplyr)
sessionInfo()
R version 3.4.3 (2017-11-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

... some output removed ...

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base   

other attached base packages:
[1] dplyr_0.7.7
R For SAS Users

Let's get started on your first R session

R For SAS Users

Preparing Video For Download...