Using the Displayr Cloud Drive R API
The Displayr Cloud Drive offers a way for licensed 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 flipAPI
package.
Sharing files with flipAPI
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:
QFileExists('test.csv')
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:
QLoadData('test.rds')
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):
QLoadData('test.rds',company_secret)
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:
QSaveData(my.data,'test_data.csv')
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')
read.csv(con)
A second example shows how to write data to a csv file using this function:
con = QFileOpen('temp.csv', open='w')
write.csv(data,con)
close(con)
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 QFileExists
, QLoadData
, QSaveData
, QOpenFile
for more details.