After starting RStudio a window opens where we can distinguish:
Console – similar to the console after launching R.exe, where you can directly enter code.
Environment window – here all stored variables and functions are displayed. The environment can be saved as well as loaded. This window also allows you to import data from outside and view the history of the lines of code entered.
Tabbed window – here you can browse the file structure on your hard disk (Files tab), view diagrams (Plots), view installed packages (Packages), search help for functions in the packages (Help).
In R, we usually want to write scripts that consist of many lines that we then want to run. To open a new script, use the Add R Script icon or the keyboard shortcut Ctrl+Shift+N. In the subwindow that opens, we can enter the script code.
In our scripts, we usually use functions created by others. In R, these are called packages. Such packages, which are useful in GIS and in remote sensing, are certainly raster libraries for raster processing or rgeos for spatial analysis. How to install them? There are two ways:
- via the console and typing install.packages(‘package name’)
- or select Tools -> Install Packages… from the main menu in RStudio and search for the desired package in the rstudio-install_packages window that pops up
Once it is installed, all you need to do is initialize it in a script or on the console using the library(package name) function.
In this entry, we want to focus specifically on R tools for geospatial data analysis and remote sensing, so we won’t go into the basics of the R language here. Here are links to some of them, which I also used at the beginning: