Opal Files

Yannick Marcon

2024-09-18

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, "/home/administrator/CNSIM.zip")

Download a file, protected by a password:

opal.file_download(o, "/home/administrator/CNSIM.zip", "CNSIM-encrypted.zip", key="ABCDEFGHIJKL")

Upload the file at another location:

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

Create a folder and list folder content:

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

Move file to the new folder and list folder content:

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

Rename the new folder and list folder content:

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

Extract the content of the archive file into a folder:

out <- opal.file_unzip(o, paste0(barDir, "/CNSIM.zip"), barDir)
opal.file_ls(o, out)

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

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

Read back the file into the Opal file system:

opal.file_read(o, "CNSIM.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/CNSIM")

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

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