Start R – First steps with R and RStudio

DUBii – Statistics with R

Claire Vandiedonck & Jacques van Helden

2020-03-10

Connection to IFB RStudio server

In a Web browser, open a connection to the IFB RStudio server

https://rstudio.cluster.france-bioinformatique.fr/

This requires your login and password.

Check the version of R and of loaded packages.

## Print info about the session
sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS/LAPACK: /usr/lib64/R/lib/libRblas.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] knitr_1.21

loaded via a namespace (and not attached):
 [1] compiler_3.5.1  magrittr_1.5    tools_3.5.1     htmltools_0.4.0 yaml_2.2.0      Rcpp_1.0.3      stringi_1.4.6   rmarkdown_1.11  stringr_1.4.0   xfun_0.4        digest_0.6.25   rlang_0.4.5     evaluate_0.12  

Defining a specific directory for this session

We will create a specific directory to store the data and results of the practicals for this course. For this we use the function file.path() to concatenate subfolders.

## Define the directory for this course
courseDir <- file.path("~", "dubii20", "stat-R", "session1")
print(courseDir) ## Check the result

Creating a directory for this session

Use the command dir.create() to create the directory definedcourseDir defined in the previous slide.

## Create the directory
dir.create(courseDir) ## THIS WILL LIKELY NOT WORK

The above command returned an error. Do you understand why? If not read the help page and find a way to solve the problem.

help(dir.create )

Creating a directory for this session

Solution:

## Create the directory with the recursive option
dir.create(path = courseDir, recursive = TRUE)

Now, re-run the same command and check the result.

## Create the directory with the recursive option
dir.create(path = courseDir, recursive = TRUE)

Creating a directory for this session

## Create the directory with the recursive option
dir.create(path = courseDir, 
           recursive = TRUE, ## Create the parent directories
           showWarnings = FALSE) ## Don't shout it already exists

## Go to this directory
setwd(courseDir)
getwd() ## Check that you are in the right place

Load the data for this course

Data and files are stored on the cluster in the directory /shared/projects/dubii2020/data/module3/seance1/

We will download the data Prerequis.RData that you saved during the prerequisites session.

## Define the path of the files
data_path <- "/shared/projects/dubii2020/data/module3/seance1/"
print(data_path) ## Check the result

## Load the data from this path
load(paste(data_path, "Prerequis.RData", sep=""))

## List the data you have dowloaded, check their struture and keep in your session only the three vectors called size, weight and bmi as well as the matrix called myData2
ls()

## to complete on your own with `rm()`

Finally, open the script DUBii_R_Session1.R stored in the same directory as the data.