The RStudio IDE cheat sheet gives a very complete and detailed overview of RStudio. Have a look at it.
Type for example
x <- c(3, 34, 12 40)
in the console then press enter. You should get this result.
The “Environment” panel on the top right side shows all the variables already used.
To print the content of the variable x
, type in the console
x
then press enter.
To see what is your current working directory, type in the console
getwd() # get working directory
then press enter.
To set another working directory, type in the console
setwd("YOUR_DIRECTORY") # set working directory
then press enter. The variable "YOUR_DIRECTORY"
is either:
setwd("mysubfolder/run")
)setwd("C:/RCourse/mysubfolder/run")
).WARNING You need to use the forward slash /
as it is on Linux or Mac system.
Alternatively, you can use the function file.path
to correctly construct/assemble the file path:
setwd(file.path("C:", "RCourse", "mysubfolder", "run"))
Then check if the path has been correctly set by typing getwd()
in the console.
Notice that the files panel on the right changed!
You can also set the working directory through the menu interface of RStudio (see below):
R packages are collections of functions and data sets. The official R repository for package is the Comprehensive R Archive Network. You can:
Have a look at the documentation of the package RConics
:
Packages can be installed by typing in the console
install.packages(c("RConics", "plot3D"))
where c("RConics", "plot3D")
is the vector of packages you want to install.
Alternatively, you can install a package through the menu interface of RStudio (see below):
Once a package is installed, you need to load it in your current session to use it.
Load the packages RConics
and plot3D
with the function library()
:
library("RConics")
library("plot3D")
Normally you organise your code in a script file and then run it into the R console
Either use the “run” button:
or select the code to run and press [Ctrl] + [Enter]
: