In workspaces, there exists a specific function, xaputils, that has been created to allow workspace users to use the Database tables or Files that have been created in their workspace in their analysis and to run SQL and R scripts.
This article explains how to use the xaputils package inside of the Built-in Apps, for information on how to use it in the R Console, see this article and how to read and write data in Python in this article.
CSV files stored in the workspace Files can easily be read and written from and to the Built-in Apps.
Reading CSV files
Reading CSV files from the Files folder:
dataset <- read.csv("~/files/your_folder/file_name.csv")
Writing CSV files
Writing CSV files to the Files folder:
You can import or export data tables stored in the workspace Database table tab either by using platform-specific functions (see 'Running XAP and R commands' below) or standard R libraries for interfacing with databases such as DBI or RPostgreSQL.
Importing database tables
The simplest way to import a database table is to use a XAP function:
dataset <- xaputils::xap.read_table("dataset_name")
You can also read a workspace data table using the DBI library:
dataset <- dbReadTable(xaputils::xap.conn, "dataset_name")
To list all the tables and database views in the current workspace, run:
Writing to the Database table tab
The following XAP function writes a data frame to a table in the Database table tab. Note if a database table with that name already exists, the function will overwrite it:
Alternatively, you can use the DBI library to do this. If a table with that name already exists, the function will raise an error. However, if you do want to append to an existing dataset, you can set
append parameter to
TRUE, or to overwrite a table, set
dbWriteTable(xaputils::xap.conn, "dataset_name", dataset)
Running XAP and R commands
XAP is an R package for interfacing with the workspace from the Built-in Apps. XAP includes functions for reading and writing to the Database table and Files tabs, creating PDFs, running SQL or R scripts.
You can display the full list of platform-specific functions by running:
To install other packages after running this command, you need to detach the xaputils package as its method of installation is not compatible with the package manager.
If you want to learn more about a specific XAP function, you can print out its documentation in the Built-in Apps: