--- title: "Start R -- First steps with R and RStudio" author: "Claire Vandiedonck & Jacques van Helden" date: "`r Sys.Date()`" output: slidy_presentation: font_adjustment: 0 ## set to negative/positive values for smaller/bigger fonts duration: 45 self_contained: no fig_caption: yes fig_height: 6 fig_width: 7 highlight: tango incremental: no keep_md: yes smaller: yes theme: cerulean toc: yes widescreen: yes beamer_presentation: colortheme: dolphin fig_caption: yes fig_height: 6 fig_width: 7 fonttheme: structurebold highlight: tango incremental: no keep_tex: no slide_level: 2 theme: Montpellier toc: yes pdf_document: fig_caption: yes highlight: zenburn toc: yes toc_depth: 3 revealjs::revealjs_presentation: theme: night transition: none self_contained: true css: ../../slides.css html_document: self_contained: no fig_caption: yes fig_height: 6 fig_width: 7 highlight: tango incremental: no keep_md: yes smaller: yes theme: cerulean toc: yes toc_depth: 3 toc_float: yes widescreen: yes ioslides_presentation: self_contained: no css: slides.css fig_caption: yes fig_height: 6 fig_width: 7 highlight: tango smaller: yes toc: yes widescreen: yes font-import: http://fonts.googleapis.com/css?family=Risque subtitle: DUBii -- Statistics with R font-family: Garamond transition: linear --- ```{r include=FALSE, echo=FALSE, eval=TRUE} library(knitr) options(width = 300) knitr::opts_chunk$set( fig.width = 7, fig.height = 5, out.width = "80%", fig.align = "center", fig.path = "figures/start-R_", size = "tiny", echo = TRUE, eval = TRUE, warning = FALSE, message = FALSE, results = TRUE, comment = "") # knitr::asis_output("\\footnotesize") # dir.main <- "~/stat1" # dir.slides <- file.path(dir.main, "slides") # setwd(dir.slides) ``` ## Connection to IFB RStudio server In a Web browser, open a connection to the IFB RStudio server This requires your login and password. Check the version of R and of loaded packages. ```{r eval=TRUE} ## Print info about the session sessionInfo() ``` ## Navigating in your folders ### Where am I? ```{r eval=FALSE} ## Where am I now? getwd() ## Where is my home? Sys.getenv("HOME") ## Who am I? Sys.getenv("LOGNAME") ## Go home setwd(Sys.getenv("HOME")) setwd("~") ## An easier way ``` ### Explanations - `Sys.getenv()` returns all the environment variables - `$HOME` is a Unix variable environment indicating the home directory - `$LOGNAME` is my login name (did you guess?) - in Unix, `~` denotes your home directory (equivalent to `$HOME`) ## 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. ```{r eval=FALSE} ## 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 defined`courseDir` defined in the previous slide. ```{r eval=FALSE} ## 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. ```{r} help(dir.create ) ``` ## Creating a directory for this session **Solution:** - The command `dir.create()` refused to create a subdirectory (`session1`) because its parent directories (`dubii2020` and `stat-R`) did not exist. - We can use the option `recursive= TRUE` to create. ```{r eval=FALSE} ## Create the directory with the recursive option dir.create(path = courseDir, recursive = TRUE) ``` Now, re-run the same command and check the result. ```{r eval=FALSE} ## Create the directory with the recursive option dir.create(path = courseDir, recursive = TRUE) ``` ## Creating a directory for this session ```{r eval=FALSE} ## 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. ```{r eval=FALSE} ## 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.