Base R is an extremely powerful tool. However…
The syntax editor in Base R is just a simple text editor.
Rstudio is relatively more efficient and easy to use.
There are actually many options:
RStudio offers:
RStudio offers:
RStudio is also an excellent tool for reproducible research.
Everyone who uses RStudio benefits from easier scripting:
It even makes working at the console viable.
Knowing a few shortcuts can save a lot of time in the long run.
Examples (Windows and Linux):
Run current line: Ctrl+Entr
Copy up/down: Ctrl+Shft+up/down
Move up/down: Shft+up/down
Run everything: Ctrl+Shft+Entr
Insert section: Ctrl+Shft+R
Select Window: Ctrl+1:9
Multicursor: Ctrl + Alt + select
(Copy) Move lines: (shift+) alt + arrow
Clear console: Ctrl + L
Restart R: Ctrl + Shft + F10
Scripting/Console Window: Ctrl+1/Ctrl+2
Rerun previous: Ctrl + Shft + P
Run everything before: Ctrl + Alt + B
Run everything before: Ctrl + Alt + E
Knit: Ctrl + Shft + K
Knowing just a dozen shortcuts could save a lot of time.
You can customize them however you want.
Mac users: most of these would use Cmd and Option rather than Ctrl and Alt
Snippets allow one to insert code of a certain form for commonly used functions.
You only have to type the first couple letters, the form of the rest of the code will fill out, then you can tab your way through the rest of it.
Good for:
RStudio will note problems in your code in the margin.
This works beyond just R scripts too!
Customize various aspects of how RStudio
Can apply to all RStudio sessions or for a particular project.
Start with the looks:
While you may certainly want to change things such as the look, to not save the workspace automatically etc., the main point is simply to be aware of what you can change.
Projects provide a self-contained ecosystem to work in.
You can easily jump between multiple projects.
File/New Project
We’ll talk about version control later.
All tabs opened will remain open when you revisit the project.
You can have multiple projects running at the same time
Help you get more organized.
Help you get more reproducible.
R is fast becoming a general programming environment
Markdown is a markup language.
Now one can intermingle R with markdown, html, css, JavaScript, \(\LaTeX\) and others resulting in a variety of products.
Rstudio and Rmarkdown make it easy to construct:
Literate programming!
Reproducible research!
R chunks are interspersed throughout the Rmd file.
Rmarkdown documents combine:
Once ready, knit the document into the format your want.
An Rmarkdown workshop will be given with more details.
Notebooks provide a different way to interact with R.
Previously one could save out some files as a ‘notebook’.
Now one can start an interactive R script.
Output is visible at the point where the code is written.
File/New File/R Noteboook…
You may still want to use (or prefer) the console
The viewer will allow for previews of the final document.
Notebooks are a different flavor of Rmarkdown document.
Good for sharing your work.
See also, Jupyter.
Along with the Plots pane, RStudio provides a Viewer pane.
Anything interactive will be displayed there.
ggplot2 is the most widely used package for visualization in R.
However, it does not produce interactive plots by nature.
Many packages use various Javascript libraries to provide interactive graphics.
Many utilize these packages via the htmlwidgets R package.
Some packages to note:
Works in your presentations too.
Shiny is a framework that can essentially allow you to build an interactive website.
Most of the more recently developed visualization packages will work specifically within the shiny and rmarkdown settings.
RStudio lets you take a deeper look at your data more easily.
Accessible interactivity.
Interactive graphics are more fun too!
Just a couple visualization packages can go a very long way.
One can create functions that can be used within RStudio with a click or keystroke.
These special functions are called addins.
Increase your productivity and efficiency when scripting.
They can be anything.
Addins are in some sense nothing more than R functions that you can call interactively.
likeR()
I like R!
However, they can possibly do quite a bit.