1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
7 #' List all resources even if the number of items is greater than maximum API limit.
9 #' @param fn Arvados method used to retrieve items from REST service.
10 #' @param ... Optional arguments which will be pased to fn .
13 #' arv <- Arvados$new("your Arvados token", "example.arvadosapi.com")
14 #' cl <- listAll(arv$collections.list, filters = list(list("name", "like", "test%"))
17 listAll <- function(fn, ...)
20 itemsAvailable <- .Machine$integer.max
23 while(length(items) < itemsAvailable)
25 serverResponse <- fn(offset = offset, ...)
27 if(!is.null(serverResponse$errors))
28 stop(serverResponse$errors)
30 items <- c(items, serverResponse$items)
31 offset <- length(items)
32 itemsAvailable <- serverResponse$items_available
39 #NOTE: Package private functions
41 trimFromStart <- function(sample, trimCharacters)
43 if(startsWith(sample, trimCharacters))
44 sample <- substr(sample, nchar(trimCharacters) + 1, nchar(sample))
49 trimFromEnd <- function(sample, trimCharacters)
51 if(endsWith(sample, trimCharacters))
52 sample <- substr(sample, 0, nchar(sample) - nchar(trimCharacters))
57 RListToPythonList <- function(RList, separator = ", ")
59 pythonArrayContent <- sapply(RList, function(elementInList)
61 if((is.vector(elementInList) || is.list(elementInList)) &&
62 length(elementInList) > 1)
64 return(RListToPythonList(elementInList, separator))
68 return(paste0("\"", elementInList, "\""))
72 pythonArray <- paste0("[", paste0(pythonArrayContent, collapse = separator), "]")
76 appendToStartIfNotExist <- function(sample, characters)
78 if(!startsWith(sample, characters))
79 sample <- paste0(characters, sample)
84 splitToPathAndName = function(path)
86 path <- appendToStartIfNotExist(path, "/")
87 components <- unlist(stringr::str_split(path, "/"))
89 nameAndPath$name <- components[length(components)]
90 nameAndPath$path <- trimFromStart(paste0(components[-length(components)], collapse = "/"),