- Are you just getting started with R or TERR?
- Are you struggling with installing packages?
- Does it seem like RStudio or R and TERR work differently when it comes to installing packages?
Learning R (or any new programming language) has its challenges, especially if you don’t have a coding background. This is even more complicated if you are trying to apply R in Spotfire using TERR. They are very similar, but small differences can give you headaches. This post will discuss the subtle difference between installing packages in TERR and RStudio or R.
Installing packages in R, RStudio, and the TERR console work exactly the same way. Simply run the install.packages function with the package name in quotes and then attach it to the library using the library function. You don’t have to install packages every time you open a session, but you do need to attach them to the library at the start of each session in order to use them. This is the case because over time, you will accumulate many packages, and it doesn’t make sense for R or RStudio or TERR to load all of them everytime you open a new session. That would take up a lot of memory. Thus, the library function makes the package available to use. You can also run installed.packages() to see a list of all installed packages.
To show you via example, review the screenshot below that demonstrates installing the RODBC package. I created two objects that I wanted to call using the odbcDriverConnect function, which is part of the RODBC package. However, R didn’t recognize the function because the package was not attached to the library. I simply attached it to the library and continued.
Package Management in Spotfire
Now, let’s take a look at TERR. Spotfire developers have created an awesome interface for users so that they don’t have to actually run the install.pakackages or library functions. Simply go to the Tools menu and choose TERR Tools. This will open dialog boxes shown below.
Go to the Package Management tab. From within Package Management, you can select a CRAN repository, install packages, and attach packages to the library. The best part is that the interface runs the install.packages() and library() functions for you. You do not have to include these functions in your TERR code.
Since we are on the subject, I also want to point out a nice feature in RStudio. Below I have copied and pasted a screenshot of a new session of RStudio. In a previous session of RStudio, I ran install.packages(“RODBC”). The next time RStudio was opened, the RODBC package was shown in the Packages pane. Clicking the checkbox next to it runs the library command.
Now you are prepared to install packages in TERR, RStudio and R. To get started with TERR data functions, try this post next on TERR basics.