[1] 11
2025-09-09
This presentation provides an introduction to R and RStudio.
It covers topics to be used in courses that require such introduction, including TAM’s courses Ecologia Numérica and Modelação Ecológica at FCUL.
Therefore you are most likely seeing it a class being delivered, unless you are working on your own.
This document could be also used as an introduction to the self-paced learning github repository hosted at https://github.com/TiagoAMarques/AnIntro2RTutorial
The tutorial has a landing webpage (and hence looks a bit friendlier) here:
https://tiagoamarques.github.io/AnIntro2RTutorial/
This document is also available online at RPubs at
You can get all the material by downloading and unziping the github repository contents. See image below: press the button at the end of the red arrow, then that of the blue arrow, and finally unzip the material into a folder of your choice.
Obtain a working knowledge about the R software and environment, to be able to implement basic data analysis
Integration of R and RStudio, an helpful R interface, via a short introduction to R and RStudio followed by a hands on assisted tutorial
I am using version 4.3.1 (2023-06-16) (those guys are fast…this will probably be outdated!)
In Giorgi et al. 2022 The R Language: An Engine for Bioinformatics and Data Science Life 12: 648 DOI: 10.3390/life12050648
image source at r4stats.com - different sources provide different numbers, but overall patters are the same
R HAS AMAZING (ENDLESS) ONLINE RESOURCES
https://resources.numbat.space/index.html
Let us create a dynamic report from scratch in RMarkdown via RStudio
Let us create a dynamic report from scratch in RMarkdown via RStudio
This is what you should be seeing. Check your title and name are there.
To do so press the “Knit” button. After you do you are asked to save the files, tell RStudio where it should do so it and what is the file name (I am using “My1stDynamicReport.Rmd”)
Regarding “latin” characters showing, like say “é”, “õ” and â”
Your first dynamic report is ready
Unless you have customized RStudio to do otherwise, the html appears in a new window. To have it in the viewer pane, change the options under Tools| Global Options
Your now have your first HTML automatically generated, obtained from compiling (=knitting) the .Rmd file (“My1stDynamicReport.Rmd”).
Actually, the output could also be a Word file or a PDF.
Not all possible features are available in word
Generating PDF’s requires some additional software (LaTex) - you can try that on your own. Good luck ;)
Try to insert a new bit of code with Code|insert chunck
(shortcut Ctrl+Al+I
)
Change a chunck’s options (e.g. eval
, echo
, etc) from TRUE
to FALSE
and see what whappens to the output
Try to use dynamic numbers like this one: -0.3658839 printing the mean value of 5 random Gaussian numbers. For that you need to use something like `? mean(rnorm(5))` (note: replace the “?” with the leter “r” so that it knows you want to run r code).
For more, check e.g. the RMarkdown cheat sheet
When you run some code within a .Rmd, it is only run in the .Rmd
When you run some code in the command line, it is only run in the command line
Therefore, reading the data in the command line does NOT mean it will be available for a dynamic report, and vice versa!
It is much safer to compile the entire document than to run code chunks separately
An .Rmd is not a usual script, it has both code and text. The result is a dynamic document, with Text, Code, and OUTPUTS of the code
The code must go always, always, always inside a code chunck!
Comments to the code can also be within code chunks (preceded by “#” – the hash symbol).
An RMarkdown template with lots of tips and trick made just for YOU here
About R Markdown, the oficial site here
The online free book
Chapter 27 on RMarkdown from the fRee online book: R FOR DATA SCIENCE here
-how to write a book with markdown, with several VERY USEFUL BOOK examples available for free here
BE PROACTIVE: EXPLORE RESOURCES
Open the hands on R tutorial (“TAMsIntro2RviaRStudioTutorial.pdf”) and work through it
It is because you either:
Next couple of slides are about learning more about R on your own. Besides all the stuff at the landing page of my github repository here:
https://github.com/TiagoAMarques/AnIntro2RTutorial
You can try a couple of things
A great place to start Ten simple rules for teaching yourself R
You can find one within the swirl R package: try it out!
The path to R mastery is winding, but the reward is worth it…