1 [comment]: # (Copyright (c) The Arvados Authors. All rights reserved.)
3 [comment]: # (SPDX-License-Identifier: CC-BY-SA-3.0)
7 This SDK focuses on providing support for accessing Arvados projects, collections, and the files within collections.
8 The API is not final and feedback is solicited from users on ways in which it could be improved.
13 knitr::opts_chunk$set(eval=FALSE)
17 install.packages("ArvadosR", repos=c("https://r.arvados.org", getOption("repos")["CRAN"]), dependencies=TRUE)
20 Note: on Linux, you may have to install supporting packages.
25 yum install libxml2-devel openssl-devel curl-devel
31 apt-get install build-essential libxml2-dev libssl-dev libcurl4-gnutls-dev
34 Minimum R version required to run ArvadosR is 3.3.0.
41 * Load Library and Initialize API:
45 # use environment variables ARVADOS_API_TOKEN and ARVADOS_API_HOST
48 # provide them explicitly
49 arv <- Arvados$new("your Arvados token", "example.arvadosapi.com")
52 Optionally, add numRetries parameter to specify number of times to retry failed service requests.
56 arv <- Arvados$new("your Arvados token", "example.arvadosapi.com", numRetries = 3)
59 This parameter can be set at any time using setNumRetries
66 #### Working with collections
71 collection <- arv$collections.get("uuid")
74 Be aware that the result from `collections.get` is _not_ a
75 `Collection` class. The object returned from this method lets you
76 access collection fields like "name" and "description". The
77 `Collection` class lets you access the files in the collection for
78 reading and writing, and is described in the next section.
83 # offset of 0 and default limit of 100
84 collectionList <- arv$collections.list(list(list("name", "like", "Test%")))
86 collectionList <- arv$collections.list(list(list("name", "like", "Test%")), limit = 10, offset = 2)
88 # count of total number of items (may be more than returned due to paging)
89 collectionList$items_available
91 # items which match the filter criteria
95 * List all collections even if the number of items is greater than maximum API limit:
98 collectionList <- listAll(arv$collections.list, list(list("name", "like", "Test%")))
101 * Delete a collection:
104 deletedCollection <- arv$collections.delete("uuid")
107 * Update a collection's metadata:
110 updatedCollection <- arv$collections.update(list(name = "New name", description = "New description"), "uuid")
113 * Create a new collection:
116 newCollection <- arv$collections.create(list(name = "Example", description = "This is a test collection"))
120 #### Manipulating collection content
122 * Initialize a collection object:
125 collection <- Collection$new(arv, "uuid")
131 files <- collection$getFileListing()
134 * Get ArvadosFile or Subcollection from internal tree-like structure:
137 arvadosFile <- collection$get("location/to/my/file.cpp")
143 arvadosSubcollection <- collection$get("location/to/my/directory/")
149 arvadosFile <- collection$get("myinput.txt")
150 arvConnection <- arvadosFile$connection("r")
151 mytable <- read.table(arvConnection)
157 arvadosFile <- collection$create("myoutput.txt")[[1]]
158 arvConnection <- arvadosFile$connection("w")
159 write.table(mytable, arvConnection)
163 * Write to existing file (overwrites current content of the file):
166 arvadosFile <- collection$get("location/to/my/file.cpp")
167 arvadosFile$write("This is new file content")
170 * Read whole file or just a portion of it:
173 fileContent <- arvadosFile$read()
174 fileContent <- arvadosFile$read("text")
175 fileContent <- arvadosFile$read("raw", offset = 1024, length = 512)
178 * Get ArvadosFile or Subcollection size:
181 size <- arvadosFile$getSizeInBytes()
187 size <- arvadosSubcollection$getSizeInBytes()
190 * Create new file in a collection (returns a vector of one or more ArvadosFile objects):
193 collection$create(files)
199 mainFile <- collection$create("cpp/src/main.cpp")[[1]]
200 fileList <- collection$create(c("cpp/src/main.cpp", "cpp/src/util.h"))
203 * Delete file from a collection:
206 collection$remove("location/to/my/file.cpp")
209 You can remove both Subcollection and ArvadosFile.
210 If subcollection contains more files or folders they will be removed recursively.
212 You can also remove multiple files at once:
215 collection$remove(c("path/to/my/file.cpp", "path/to/other/file.cpp"))
218 * Delete file or folder from a Subcollection:
221 subcollection <- collection$get("mySubcollection/")
222 subcollection$remove("fileInsideSubcollection.exe")
223 subcollection$remove("folderInsideSubcollection/")
226 * Move or rename a file or folder within a collection (moving between collections is currently not supported):
228 Directly from collection
231 collection$move("folder/file.cpp", "file.cpp")
237 file <- collection$get("location/to/my/file.cpp")
238 file$move("newDestination/file.cpp")
241 Or from subcollection
244 subcollection <- collection$get("location/to/folder")
245 subcollection$move("newDestination/folder")
248 Make sure to include new file name in destination.
249 In second example file$move("newDestination/") will not work.
251 * Copy file or folder within a collection (copying between collections is currently not supported):
253 Directly from collection
256 collection$copy("folder/file.cpp", "file.cpp")
262 file <- collection$get("location/to/my/file.cpp")
263 file$copy("destination/file.cpp")
266 Or from subcollection
269 subcollection <- collection$get("location/to/folder")
270 subcollection$copy("destination/folder")
273 #### Working with Aravdos projects
278 project <- arv$projects.get("uuid")
284 list subprojects of a project
285 projects <- arv$projects.list(list(list("owner_uuid", "=", "aaaaa-j7d0g-ccccccccccccccc")))
287 list projects which have names beginning with Example
288 examples <- arv$projects.list(list(list("name","like","Example%")))
291 * List all projects even if the number of items is greater than maximum API limit:
294 projects <- listAll(arv$projects.list, list(list("name","like","Example%")))
300 deletedProject <- arv$projects.delete("uuid")
306 updatedProject <- arv$projects.update(list(name = "new_name", description = "new description"), "uuid")
312 newProject <- arv$projects.update(list(name = "project_name", description = "project description"))
317 * View help page of Arvados classes by puting ? before class name:
326 * View help page of any method defined in Arvados class by puting ? before method name:
333 ### Building the ArvadosR package
336 cd arvados/sdk && R CMD build R
339 This will create a tarball of the ArvadosR package in the current directory.