Business Intelligence Tools / Developers Corner

Installing Packages in TERR versus RStudio and R

  • 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

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.

Installing packages

You may also be asked to select a CRAN repository (depending on whether or not this is a brand new session and your first package).
install.packages(“package”) uses quotes around the package name library(package) does not use quotes around the package name

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.

Attach to Library


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.

TERR Tools Menu


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.  Technically, you do not have to include these functions in your TERR code.  However, just like RStudio, TERR requires that you attach the package to the library at the start of each new session.  Thus, I recommend including the library(package) command at the start of all your TERR code.

Spotfire GUI


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.

RStudio GUI

RStudio Attach to Library

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.



1 thought on “Installing Packages in TERR versus RStudio and R

  1. Pingback: TERR Scripts to Read/Write to MS Access - Data Shop Talk

Leave a Reply

Your email address will not be published. Required fields are marked *