# Exporting the Data Function Results

Being able to examine the data and the code outside of Spotfire Analyst is an important capability in developing robust data functions.

## About this task

This example builds on the data function created in the example Debugging a Simple Data Function. You can export any data function using th code in this example.

## Before you begin

- You must have the advanced analytics license to use the TERR toolset. If you do not have this license, see your Spotfire administrator.
- You must have RStudio installed on your computer. for more information, see Configure RStudio to use Spotfire Enterprise Runtime for R.
- You must have Enabling Debugging for Data Functions.
- You must have completed the example Debugging a Simple Data Function, or you must have your own data function that you want to debug.

## Procedure

1. On the Spotfire Analyst menu, click Edit > Data Function Properties, and then in the Data Function Properties dialog box, click Edit Script to return to the data function script.
2. Add the following code to the top of the data function.

       z <- getOption("debug.spotfireConnector", FALSE)
       if (z) save(list=ls(), file="C:/temp/debug.RData", RFormat=TRUE)

   This function determines whether the debugging option for TERR is set, and if it is, the data function debugging results are written to an .RData file. You can specify any directory, as long as you have write access to the directory.
3. Save the data function, and then click Refresh to run it.
   You can review the debugging results in the Notifications dialog box, if you want to.
4. From the Tools > TERR Tools menu, open TERR Tools, and then open RStudio.
   RStudio development environment opens, running TERR.
5. Open the .RData file you created by running the data function, and then examine the results.