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("http://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")
77 # offset of 0 and default limit of 100
78 collectionList <- arv$collections.list(list(list("name", "like", "Test%")))
80 collectionList <- arv$collections.list(list(list("name", "like", "Test%")), limit = 10, offset = 2)
84 # count of total number of items (may be more than returned due to paging)
85 collectionList$items_available
87 # items which match the filter criteria
91 * List all collections even if the number of items is greater than maximum API limit:
94 collectionList <- listAll(arv$collections.list, list(list("name", "like", "Test%")))
97 * Delete a collection:
100 deletedCollection <- arv$collections.delete("uuid")
103 * Update a collection's metadata:
106 updatedCollection <- arv$collections.update(list(name = "New name", description = "New description"), "uuid")
112 newCollection <- arv$collections.create(list(name = "Example", description = "This is a test collection"))
116 #### Manipulating collection content
118 * Create collection object:
121 collection <- Collection$new(arv, "uuid")
127 files <- collection$getFileListing()
130 * Get ArvadosFile or Subcollection from internal tree-like structure:
133 arvadosFile <- collection$get("location/to/my/file.cpp")
139 arvadosSubcollection <- collection$get("location/to/my/directory/")
145 arvadosFile <- collection$get("myinput.txt")
146 arvConnection <- arvadosFile$connection("r")
147 mytable <- read.table(arvConnection)
153 arvadosFile <- collection$create("myoutput.txt")
154 arvConnection <- arvadosFile$connection("w")
155 write.table(mytable, arvConnection)
159 * Write to existing file (override current content of the file):
162 arvadosFile <- collection$get("location/to/my/file.cpp")
163 arvadosFile$write("This is new file content")
166 * Read whole file or just a portion of it:
169 fileContent <- arvadosFile$read()
170 fileContent <- arvadosFile$read("text")
171 fileContent <- arvadosFile$read("raw", offset = 1024, length = 512)
174 * Get ArvadosFile or Subcollection size:
177 size <- arvadosFile$getSizeInBytes()
183 size <- arvadosSubcollection$getSizeInBytes()
186 * Create new file in a collection:
189 collection$create(files)
195 mainFile <- collection$create("cpp/src/main.cpp")
196 fileList <- collection$create(c("cpp/src/main.cpp", "cpp/src/util.h"))
199 * Delete file from a collection:
202 collection$remove("location/to/my/file.cpp")
205 You can remove both Subcollection and ArvadosFile.
206 If subcollection contains more files or folders they will be removed recursively.
208 You can also remove multiple files at once:
211 collection$remove(c("path/to/my/file.cpp", "path/to/other/file.cpp"))
214 * Delete file or folder from a Subcollection:
217 subcollection <- collection$get("mySubcollection/")
218 subcollection$remove("fileInsideSubcollection.exe")
219 subcollection$remove("folderInsideSubcollection/")
222 * Move or rename a file or folder within a collection (moving between collections is currently not supported):
224 Directly from collection
227 collection$move("folder/file.cpp", "file.cpp")
233 file <- collection$get("location/to/my/file.cpp")
234 file$move("newDestination/file.cpp")
237 Or from subcollection
240 subcollection <- collection$get("location/to/folder")
241 subcollection$move("newDestination/folder")
244 Make sure to include new file name in destination.
245 In second example file$move("newDestination/") will not work.
247 * Copy file or folder within a collection (copying between collections is currently not supported):
249 Directly from collection
252 collection$copy("folder/file.cpp", "file.cpp")
258 file <- collection$get("location/to/my/file.cpp")
259 file$copy("destination/file.cpp")
262 Or from subcollection
265 subcollection <- collection$get("location/to/folder")
266 subcollection$copy("destination/folder")
269 #### Working with Aravdos projects
274 project <- arv$projects.get("uuid")
280 list subprojects of a project
281 projects <- arv$projects.list(list(list("owner_uuid", "=", "aaaaa-j7d0g-ccccccccccccccc")))
283 list projects which have names beginning with Example
284 examples <- arv$projects.list(list(list("name","like","Example%")))
287 * List all projects even if the number of items is greater than maximum API limit:
290 projects <- listAll(arv$projects.list, list(list("name","like","Example%")))
296 deletedProject <- arv$projects.delete("uuid")
302 updatedProject <- arv$projects.update(list(name = "new_name", description = "new description"), "uuid")
308 newProject <- arv$projects.update(list(name = "project_name", description = "project description"))
313 * View help page of Arvados classes by puting ? before class name:
322 * View help page of any method defined in Arvados class by puting ? before method name:
329 ### Building the ArvadosR package
332 cd arvados/sdk && R CMD build R
335 This will create a tarball of the ArvadosR package in the current directory.