By the end of this session, you should be able to:
workshop
folder from the USB drive to your desktopinstallers
folder and find the correct folder for your operating systemI will show you how to make your analyses reproducible. We will write code to import raw data, do some data manipulation, analyze the data and create a plot, and generate a report. This is the beginning of the end of editing raw data files and pointing and clicking your way to an analysis that is hard to reproduce.
I’ll also show you how to combine your analysis code with your write-up. This means the end is near for copying/pasting results, tables, and figures from your stats program/Excel to your report.
Tools > Global Options
You can create a new RStudio project for every real life project you have. Just tell RStudio to find the project folder on your computer. A major benefit of projects is that all of the file paths will be relative to the root directory of your project.
I created a project for you today. Find the workshop
folder on your desktop and double click on the RStudio project file. This will open our project in RStudio.
In your console run:
Since you opened our project file, R should think that your working directory is your project directory.
Every file reference should be relative to this working (root) directory.
../
goes up one level../../
goes up two levelssubdirectory/
does down one levelsubdirectory/subsubdirectory/
goes down two levelsCreate a new R script file
Create a new RMarkdown HTML file
I created a report Rmd
file for you. Look for the FILES tab and open the reports
folder.
When you knit a document, RStudio thinks that the directory where the document is saved should be the working directory. If your template is stored in workshop/reports
, for instance, reports
will become the working directory and relative file paths won’t work. To fix this, we added the following to the R code chunk named setup
:
This tells RStudio that the working directory is 1-level up from where the report file sits.
Plain text, italics, bold, monospaced font
strikethrough, sub/superscript22, endash: –, emdash: —
equation: \(A = \pi*r^{2}\)
\[E = mc^{2}\]
block quote
list:
Turn to the back of your Markdown cheatsheet and try writing some text under the “Markdown Practice” heading (e.g., bold, italics, lists, subheadings, web links, footnote). Then click “Knit” to compile the document.
## [1] NA
?mean