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(fileNames, optionalRelativePath)
195 mainFile <- collection$create("main.cpp", "cpp/src/")
196 fileList <- collection$create(c("main.cpp", lib.dll), "cpp/src/")
199 * Add existing ArvadosFile or Subcollection to a collection:
202 folder <- Subcollection$new("src")
203 file <- ArvadosFile$new("main.cpp")
208 collection$add(folder, "cpp")
211 This examples will add file "main.cpp" in "./cpp/src/" folder if folder exists.
212 If subcollection contains more files or folders they will be added recursively.
214 * Delete file from a collection:
217 collection$remove("location/to/my/file.cpp")
220 You can remove both Subcollection and ArvadosFile.
221 If subcollection contains more files or folders they will be removed recursively.
223 You can also remove multiple files at once:
226 collection$remove(c("path/to/my/file.cpp", "path/to/other/file.cpp"))
229 * Delete file or folder from a Subcollection:
232 subcollection <- collection$get("mySubcollection/")
233 subcollection$remove("fileInsideSubcollection.exe")
234 subcollection$remove("folderInsideSubcollection/")
237 * Move file or folder inside collection:
239 Directley from collection
242 collection$move("folder/file.cpp", "file.cpp")
248 file <- collection$get("location/to/my/file.cpp")
249 file$move("newDestination/file.cpp")
252 Or from subcollection
255 subcollection <- collection$get("location/to/folder")
256 subcollection$move("newDestination/folder")
259 Make sure to include new file name in destination.
260 In second example file$move("newDestination/") will not work.
262 #### Working with Aravdos projects
267 project <- arv$projects.get("uuid")
273 list subprojects of a project
274 projects <- arv$projects.list(list(list("owner_uuid", "=", "aaaaa-j7d0g-ccccccccccccccc")))
276 list projects which have names beginning with Example
277 examples <- arv$projects.list(list(list("name","like","Example%")))
280 * List all projects even if the number of items is greater than maximum API limit:
283 projects <- listAll(arv$projects.list, list(list("name","like","Example%")))
289 deletedProject <- arv$projects.delete("uuid")
295 updatedProject <- arv$projects.update(list(name = "new_name", description = "new description"), "uuid")
301 newProject <- arv$projects.update(list(name = "project_name", description = "project description"))
306 * View help page of Arvados classes by puting ? before class name:
315 * View help page of any method defined in Arvados class by puting ? before method name:
322 ### Building the ArvadosR package
325 cd arvados/sdk && R CMD build R
328 This will create a tarball of the ArvadosR package in the current directory.