Merge branch '21666-provision-test-improvement'
[arvados.git] / sdk / R / R / Collection.R
index e362de604114b3736b23c52623f8facf8c33c842..9ca74accc56eb27b33c7739980adcaa22ca7da56 100644 (file)
@@ -9,7 +9,7 @@
 #' for exaplme actions like creating, updating, moving or removing are possible.
 #'
 #' @seealso
-#' \code{\link{https://github.com/arvados/arvados/tree/main/sdk/R}}
+#' https://git.arvados.org/arvados.git/tree/HEAD:/sdk/R
 #'
 #' @export
 
@@ -28,7 +28,9 @@ Collection <- R6::R6Class(
         #' @param uuid The UUID Autentic for Collection UUID.
         #' @return A new `Collection` object.
         #' @examples
+        #' \dontrun{
         #' collection <- Collection$new(arv, CollectionUUID)
+        #' }
         initialize = function(api, uuid)
         {
             private$REST <- api$getRESTService()
@@ -89,6 +91,7 @@ Collection <- R6::R6Class(
         #' @param Ncol Used in reading binary file to set numbers of columns in data.frame.
         #' @param Nrow Used in reading binary file to set numbers of rows in data.frame size.
         #' @examples
+        #' \dontrun{
         #' collection <- Collection$new(arv, collectionUUID)
         #' readFile <- collection$readArvFile(arvadosFile, istable = 'yes')                    # table
         #' readFile <- collection$readArvFile(arvadosFile, istable = 'no')                     # text
@@ -96,6 +99,7 @@ Collection <- R6::R6Class(
         #' readFile <- collection$readArvFile(arvadosFile, fileclass = 'fasta')                # fasta
         #' readFile <- collection$readArvFile(arvadosFile, Ncol= 4, Nrow = 32)                 # binary, only numbers
         #' readFile <- collection$readArvFile(arvadosFile, Ncol = 5, Nrow = 150, istable = "factor") # binary with factor or text
+        #' }
         readArvFile = function(file, con, sep = ',', istable = NULL, fileclass = "SeqFastadna", Ncol = NULL, Nrow = NULL, wantedFunction = NULL)
         {
             arvFile <- self$get(file)
@@ -197,24 +201,18 @@ Collection <- R6::R6Class(
         #' @param file File to be saved.
         #' @param istable Used in writing txt file to check if the file is table or not.
         #' @examples
+        #' \dontrun{
         #' collection <- Collection$new(arv, collectionUUID)
-        #' writeFile <- collection$writeFile("myoutput.csv", file, istable = NULL)             # csv
-        #' writeFile <- collection$writeFile("myoutput.fasta", file, istable = NULL)           # fasta
-        #' writeFile <- collection$writeFile("myoutputtable.txt", file, istable = "yes")       # txt table
-        #' writeFile <- collection$writeFile("myoutputtext.txt", file, istable = "no")         # txt text
-        #' writeFile <- collection$writeFile("myoutputbinary.dat", file)                       # binary
-        #' writeFile <- collection$writeFile("myoutputxlsx.xlsx", file)                        # xlsx
-        writeFile = function(name, file, istable = NULL, seqName = NULL)
+        #' writeFile <- collection$writeFile(name = "myoutput.csv", file = file, fileFormat = "csv", istable = NULL, collectionUUID = collectionUUID)             # csv
+        #' writeFile <- collection$writeFile(name = "myoutput.tsv", file = file, fileFormat = "tsv", istable = NULL, collectionUUID = collectionUUID)             # tsv
+        #' writeFile <- collection$writeFile(name = "myoutput.fasta", file = file, fileFormat = "fasta", istable = NULL, collectionUUID = collectionUUID)         # fasta
+        #' writeFile <- collection$writeFile(name = "myoutputtable.txt", file = file, fileFormat = "txt", istable = "yes", collectionUUID = collectionUUID)       # txt table
+        #' writeFile <- collection$writeFile(name = "myoutputtext.txt", file = file, fileFormat = "txt", istable = "no", collectionUUID = collectionUUID)         # txt text
+        #' writeFile <- collection$writeFile(name = "myoutputbinary.dat", file = file, fileFormat = "dat", collectionUUID = collectionUUID)                       # binary
+        #' writeFile <- collection$writeFile(name = "myoutputxlsx.xlsx", file = file, fileFormat = "xlsx", collectionUUID = collectionUUID)                       # xlsx
+        #' }
+        writeFile = function(name, file, collectionUUID, fileFormat, istable = NULL, seqName = NULL)
         {
-            # prepare file and connection
-            arvFile <- collection$create(name)[[1]]
-            arvFile <- collection$get(name)
-            arvConnection <- arvFile$connection("w")
-            # get file format
-            FileName <- arvFile$getName()
-            FileName <- tolower(FileName)
-            FileFormat <- gsub(".*\\.", "", FileName)
-
             # set enviroment
             ARVADOS_API_TOKEN <- Sys.getenv("ARVADOS_API_TOKEN")
             ARVADOS_API_HOST <- Sys.getenv("ARVADOS_API_HOST")
@@ -227,22 +225,25 @@ Collection <- R6::R6Class(
                 "AWS_DEFAULT_REGION" = "collections",
                 "AWS_S3_ENDPOINT" = gsub("api[.]", "", ARVADOS_API_HOST))
 
-            if (FileFormat == "txt") {
+            # save file
+            if (fileFormat == "txt") {
                 if (istable == "yes") {
-                    aws.s3::s3write_using(file, FUN = write.table, object = name, bucket = my_collection)
+                    aws.s3::s3write_using(file, FUN = write.table, object = name, bucket = collectionUUID)
                 } else if (istable == "no") {
-                    aws.s3::s3write_using(file, FUN = writeChar, object = name, bucket = my_collection)
+                    aws.s3::s3write_using(file, FUN = writeChar, object = name, bucket = collectionUUID)
                 } else {
                     stop(paste("Specify parametr istable"))
                 }
-            } else if (FileFormat == "csv") {
-                aws.s3::s3write_using(file, FUN = write.csv, object = name, bucket = my_collection)
-            } else if (FileFormat == "fasta") {
-                aws.s3::s3write_using(file, FUN = seqinr::write.fasta, name = seqName, object = name, bucket = my_collection)
-            } else if (FileFormat == "xlsx") {
-                aws.s3::s3write_using(file, FUN = openxlsx::write.xlsx, object = name, bucket = my_collection)
-            } else if (FileFormat == "dat" || FileFormat == "bin") {
-                aws.s3::s3write_using(file, FUN = writeBin, object = name, bucket = my_collection)
+            } else if (fileFormat == "csv") {
+                aws.s3::s3write_using(file, FUN = write.csv, object = name, bucket = collectionUUID)
+            } else if (fileFormat == "tsv") {
+                aws.s3::s3write_using(file, FUN = write.table, row.names = FALSE, sep = "\t", object = name, bucket = collectionUUID)
+            } else if (fileFormat == "fasta") {
+                aws.s3::s3write_using(file, FUN = seqinr::write.fasta, name = seqName, object = name, bucket = collectionUUID)
+            } else if (fileFormat == "xlsx") {
+                aws.s3::s3write_using(file, FUN = openxlsx::write.xlsx, object = name, bucket = collectionUUID)
+            } else if (fileFormat == "dat" || fileFormat == "bin") {
+                aws.s3::s3write_using(file, FUN = writeBin, object = name, bucket = collectionUUID)
             } else {
                 stop(parse(('File format not supported, use arvadosFile$connection() and customise it')))
             }
@@ -252,7 +253,9 @@ Collection <- R6::R6Class(
         #' Creates one or more ArvadosFiles and adds them to the collection at specified path.
         #' @param files Content to be created.
         #' @examples
+        #' \dontrun{
         #' collection <- arv$collections_create(name = collectionTitle, description = collectionDescription, owner_uuid = collectionOwner, properties = list("ROX37196928443768648" = "ROX37742976443830153"))
+        #' }
         create = function(files)
         {
             if(is.null(private$tree))
@@ -286,7 +289,9 @@ Collection <- R6::R6Class(
         #' Remove one or more files from the collection.
         #' @param paths Content to be removed.
         #' @examples
+        #' \dontrun{
         #' collection$remove(fileName.format)
+        #' }
         remove = function(paths)
         {
             if(is.null(private$tree))
@@ -325,7 +330,9 @@ Collection <- R6::R6Class(
         #' @param content Content to be moved.
         #' @param destination Path to move content.
         #' @examples
+        #' \dontrun{
         #' collection$move("fileName.format", path)
+        #' }
         move = function(content, destination)
         {
             if(is.null(private$tree))
@@ -346,7 +353,9 @@ Collection <- R6::R6Class(
         #' @param content Content to be moved.
         #' @param destination Path to move content.
         #' @examples
+        #' \dontrun{
         #' copied <- collection$copy("oldName.format", "newName.format")
+        #' }
         copy = function(content, destination)
         {
             if(is.null(private$tree))
@@ -365,7 +374,9 @@ Collection <- R6::R6Class(
         #' @description
         #' Refreshes the environment.
         #' @examples
+        #' \dontrun{
         #' collection$refresh()
+        #' }
         refresh = function()
         {
             if(!is.null(private$tree))
@@ -378,7 +389,9 @@ Collection <- R6::R6Class(
         #' @description
         #' Returns collections file content as character vector.
         #' @examples
+        #' \dontrun{
         #' list <- collection$getFileListing()
+        #' }
         getFileListing = function()
         {
             if(is.null(private$tree))
@@ -392,11 +405,13 @@ Collection <- R6::R6Class(
         #' If relativePath is valid, returns ArvadosFile or Subcollection specified by relativePath, else returns NULL.
         #' @param relativePath Path from content is taken.
         #' @examples
+        #' \dontrun{
         #' arvadosFile <- collection$get(fileName)
+        #' }
         get = function(relativePath)
         {
             if(is.null(private$tree))
-                private$generateCollectionTreeStructure(relativePath)
+                private$generateCollectionTreeStructure()
 
             private$tree$getElement(relativePath)
         },
@@ -439,10 +454,3 @@ print.Collection = function(x, ...)
     cat(paste0("Type: ", "\"", "Arvados Collection", "\""), sep = "\n")
     cat(paste0("uuid: ", "\"", x$uuid,               "\""), sep = "\n")
 }
-
-
-
-
-
-
-