Workspace Interaction From R

From Gcube Wiki
Revision as of 11:03, 8 October 2020 by Gianpaolo.coro (Talk | contribs) (Functions)

Jump to: navigation, search

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

#REMOTE IMPORT OF ALL FUNCTIONS - OPTIONAL
source("http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-analysis/RConfiguration/RD4SFunctions/workspace_interaction.r")
 
#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
 
 
#CREATING A NEW FOLDER
pathonthews<-"/Home/gianpaolo.coro/Workspace"
folderName = "MyNewFolder"
newFolderID = createPrivateFolder(path=pathonthews,foldername=folderName)
checkf<-listWS("/Home/gianpaolo.coro/Workspace/MyNewFolder/")
 
#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 (FOR NON-VRE FOLDERS)
remotefile<-"/Home/gianpaolo.coro/Workspace/splist.txt"
publicURL<-getPublicFileLinkWS(remotefile)
 
#UPLOAD TO THE ROOT OF THE VRE FOLDER CORRESPONDING TO THE USER TOKEN
outcome<-uploadToVREFolder("",'sampletext2.txt',T,F)
#UPLOAD TO A SUBFOLDER OF THE VRE FOLDER
outcome<-uploadToVREFolder("Samples/",'sampletext2.txt',T,F)
#UPLOAD TO A SUBSUBFOLDER OF THE VRE FOLDER
outcome<-uploadToVREFolder("Samples/TextSamples/",'sampletext2.txt',T,F)
 
#GET FILE LINK FROM THE ROOT VRE FOLDER
link<-getPublicFileLinkVREFolder('sampletext2.txt')
 
#GET FILE LINK FROM A FILE IN A SUBFOLDER OF THE  VRE FOLDER
link<-getPublicFileLinkVREFolder('Samples/sampletext2.txt')
 
#DOWNLOAD FILE FROM THE ROOT VRE FOLDER
downloadFromVREFolder('sampletext2.txt')
 
#DOWNLOAD FILE FROM A SUBFOLDER OF THE ROOT VRE FOLDER
downloadFromVREFolder('Samples/sampletext2.txt')