Workspace Interaction From R
From Gcube Wiki
Overview
This page reports examples to interact with the online Workspace (WS) from R.
Key features
- interaction with R
- saving files and folders on the WS
- downloading files and folders from the WS
Functions
- INITIAL STEP: Import the D4Science interaction functions R container script. This step is not necessary when using the RStudio instance on one of the Web portals.
#SETTING USERNAME AND TOKEN - NOT NEEDED WHEN USING RSTUDIO ON THE PORTAL username<<-"gianpaolo.coro" token<<-"..." #YOUR TOKEN FOR A VRE #LISTING a<-listHomeWS() #GET THE LIST OF FOLDERS IN THE WS ROOT b<-listWS("/Home/gianpaolo.coro/Workspace/TestSAI/") #GET THE LIST OF FILES AND FOLDERS IN ONE SUB-FOLDER #DOWNLOADING remoteFile<-"/Home/gianpaolo.coro/Workspace/DataMiner/sample.xml" #REMOTE FILE TO DOWNLOAD downloadFileWS(remoteFile) #DOWNLOAD THE FILE LOCALLY folder<-"/Home/gianpaolo.coro/Workspace/TestSAI" #REMOTE FOLDER TO DOWNLOAD downloadFolderWS(folder) #DOWNLOAD THE FOLDER CONTENT LOCALLY #UPLOADING wsfolder<-"/Home/gianpaolo.coro/Workspace/TestUploads" #REMOTE DESTINATION FOLDER file="userconfig.csv" #LOCAL FILE TO UPLOAD overwrite<-T #CHOOSE IF THE FILE SHOULD BE OVERWRITTEN q<-uploadWS(wsfolder,file,overwrite) #UPLOAD THE FILE TO THE WS #UPLOADING THE COMPLETE LOCAL R WORKSPACE ONTO THE E-INFRA WS uploadAllWS(wsfolder) #OBTAINING A PUBLIC URL FOR A FILE (NOT AVAILABLE FOR FOLDERS) remotefile<-"/Home/gianpaolo.coro/Workspace/splist.txt" publicURL<-getPublicFileLinkWS(remotefile) #UPLOAD TO THE VRE FOLDER CORRESPONDING TO THE TOKEN id<-getVREFolderID() outcome<-uploadToVREFolder(id,'sampletext2.txt',overwrite=T,archive=F) #GET THE PUBLIC LINK OF A FILE IN A VRE FOLDER link<-getPublicFileLinkVREFolder('sampletext2.txt') #DOWNLOAD A FILE IN THE VRE FOLDER downloadFromVREFolder('sampletext2.txt')