Using the Displayr Cloud Drive R API
The Displayr Cloud Drive offers a way for Enterprise users to store and share files across your company documents. While there are various built-in ways to import and export these shared files, it is also possible to use R code via New Data Set > R or Insert > R Output. This allows you to load and save R data sets (.rds) and .csv files using a series of R functions from the
Sharing files with
To check whether a file exists within the Cloud Drive, you can use the
QFileExists function by simply specifying the name and extension of the file in question:
This will return a TRUE or FALSE.
To load an existing file stored in the Cloud Drive,
QLoadData should be used with the exact name and extension of the file:
If you have multiple companies under the same account, you can share files among your companies using the company secret key where the file is located (this can be provided on request):
Similarly, to save a file, you should use
QSaveData by passing the name of the output and then specifying the name and extension of the file:
When working with csv files,
QFileOpen is a further function for reading and writing data. The below code opens the specified csv file as read only and loads it into your R Output:
con = QFileOpen('temp.csv', open='r')
A second example shows how to write data to a csv file using this function:
con = QFileOpen('temp.csv', open='w')
Here, temp.csv is created, the contents of
data are written to it and it is then saved to the Cloud Drive.
See the R documentation for
QOpenFile for more details.