How to Debug a Spotfire Data Function in RStudio?

Have you ever come across problems and errors while running the TERR scripts in Spotfire Data Functions which you didn’t have while running the same code as an R script outside Spotfire? There is a way to troubleshoot this issue by debugging your TERR code outside of Spotfire, i.e., in RStudio. Generally speaking, you need to enable your RStudio to run the TERRengine instead of R. Then, you want to be able to access your TERR Data Function Input Parameters from RStudio so that you can run and debug your TERR script there. How to do all that? It’s not that complicted. Please follow the steps below.

If you already have RStudio installed on your machine, go to Step 2.

If your RStudio is already running TERR, go to Step 4.

  1. Download RStudio

    RStudio is the development environment for R. The Open Source version is free.

    Download: https://www.rstudio.com/products/RStudio/#Desk

  2. Find your TERR engine.

    Mine is located at C:\Program Files (x86)\TIBCO\Spotfire\7.0.0\Modules\TIBCO Enterprise Runtime for R_3.1.0.19\engine

    The TERR engine folder may be hidden. If that’s the case you need to “Show Hiden Folders” on your machine. Follow the steps listed here: https://support.microsoft.com/en-us/help/14201/windows-show-hidden-files#show-hidden-files=windows-7

  3. Point RStudio to TERR Engine
    1. In RStudio go to Tools -> Global Options…
    2. In General menu select the R version by clicking Change

    3. Click Browse and navigate to the TERR engine location.

      In my case it is C:\Program Files (x86)\TIBCO\Spotfire\7.0.0\Modules\TIBCO Enterprise Runtime for R_3.1.0.19\engine\

    4. Restart RStudio for the changes to take effect.
    5. Verify TERR is running in RStudio.

      After the restart, in the RStudio Console, you should be able to see the version of TERR running.

  4. In Spotfire, save the Data Function Input Parameters to an RData file.

    You can do that by placing the following line of code in your Data Function script. Note: the script has to run successfully, i.e., without errors, for the data to get saved.

    save(list=ls(), file=”C:/Users/Anna/Documents/regression.RData”, RFormat=TRUE)

  5. In RStudio Console load the RData file by executing the following line of code:

  6. Run your R script in RStudio using the same inputs as when you would run it in the Spotfire TERR Data Function.

5 thoughts on “How to Debug a Spotfire Data Function in RStudio?

  1. I must be missing something here… if the intent is to debug errors in RStudio, how can the line of code given (save(list=ls(), file=”LOCATION.RData”, RFormat=TRUE)) possibly run without errors?

    1. Did you try running the script as is? You will want to swap out the LOCATION for your own path to the correct directory. For the moment, we went ahead and changed it in the blog to reflect that.

  2. Note for others having issues: make sure that your file location path has all the backslashes changed to forward slashes if you copy and paste if from a link or explorer window. Also make sure that the quotations around the path at not angle, TERR gave me the following error. I replaced them and it worked.

    Thanks Anna for the post this is will be very helpful in troubleshooting.

    error message:
    TIBCO Enterprise Runtime for R returned an error: ‘Error in parse(text = script) : parse error in text argument: symbol `”C` must be written using backticks (line 1, characters 22 through 25)’.

Leave a Comment

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