Opal Files API

Yannick Marcon

2019-12-10

Opal has an internal file system that is accessible through web services. The Opal R package exposes files management related functions:

Setup the connection with Opal:

library(opalr)
o <- opal.login("administrator", "password", "https://opal-demo.obiba.org")

Download a file:

opal.file_download(o, "/tmp/datashield.zip")

Download a file, protected by a password:

opal.file_download(o, "/tmp/datashield.zip", "datashield-encrypted.zip", key="ABCDEFGHIJKL")

Upload the file at another location:

opal.file_upload(o, "datashield.zip", "/projects/datashield")

Create a folder and list folder content:

fooDir <- paste0("/projects/datashield/foo-", sample(10000:99999, 1))
opal.file_mkdir(o, fooDir)
opal.file_ls(o, "/projects/datashield")

Move file to the new folder and list folder content:

opal.file_mv(o, "/projects/datashield/datashield.zip", fooDir)
opal.file_ls(o, fooDir)

Rename the new folder and list folder content:

barDir <- paste0("/projects/datashield/bar-", sample(10000:99999, 1))
opal.file_mv(o, fooDir, barDir)
opal.file_ls(o, "/projects/datashield")

Write a file from the Opal file system into the R server session workspace:

opal.file_write(o, paste0(barDir, "/datashield.zip"))
opal.execute(o, "list.files()")

Read back the file into the Opal file system:

opal.file_read(o, "datashield.zip", paste0(barDir, "/ds.zip"))
opal.file_ls(o, barDir)

Remove created folder and list folder content:

opal.file_rm(o, barDir)
opal.file_ls(o, "/projects/datashield")

Good practice is to free server resources by sending a logout request:

# clean server side
opal.logout(o)
# clean client side
unlink("datashield-encrypted.zip")
unlink("datashield.zip")