1 [comment]: # (Copyright © 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
39 * Load Library and Initialize API:
43 # use environment variables ARVADOS_API_TOKEN and ARVADOS_API_HOST
46 # provide them explicitly
47 arv <- Arvados$new("your Arvados token", "example.arvadosapi.com")
50 Optionally, add numRetries parameter to specify number of times to retry failed service requests.
54 arv <- Arvados$new("your Arvados token", "example.arvadosapi.com", numRetries = 3)
57 This parameter can be set at any time using setNumRetries
64 #### Working with collections
69 collection <- arv$collections.get("uuid")
75 # offset of 0 and default limit of 100
76 collectionList <- arv$collections.list(list(list("name", "like", "Test%")))
78 collectionList <- arv$collections.list(list(list("name", "like", "Test%")), limit = 10, offset = 2)
82 # count of total number of items (may be more than returned due to paging)
83 collectionList$items_available
85 # items which match the filter criteria
89 * List all collections even if the number of items is greater than maximum API limit:
92 collectionList <- listAll(arv$collections.list, list(list("name", "like", "Test%")))
95 * Delete a collection:
98 deletedCollection <- arv$collections.delete("uuid")
101 * Update a collection's metadata:
104 updatedCollection <- arv$collections.update(list(name = "New name", description = "New description"), "uuid")
110 newCollection <- arv$collections.create(list(name = "Example", description = "This is a test collection"))
114 #### Manipulating collection content
116 * Create collection object:
119 collection <- Collection$new(arv, "uuid")
125 files <- collection$getFileListing()
128 * Get ArvadosFile or Subcollection from internal tree-like structure:
131 arvadosFile <- collection$get("location/to/my/file.cpp")
137 arvadosSubcollection <- collection$get("location/to/my/directory/")
143 arvadosFile <- collection$get("myinput.txt")
144 arvConnection <- arvadosFile$connection("r")
145 mytable <- read.table(arvConnection)
151 arvadosFile <- collection$create("myoutput.txt")
152 arvConnection <- arvadosFile$connection("w")
153 write.table(mytable, arvConnection)
157 * Write to existing file (override current content of the file):
160 arvadosFile <- collection$get("location/to/my/file.cpp")
161 arvadosFile$write("This is new file content")
164 * Read whole file or just a portion of it:
167 fileContent <- arvadosFile$read()
168 fileContent <- arvadosFile$read("text")
169 fileContent <- arvadosFile$read("raw", offset = 1024, length = 512)
172 * Get ArvadosFile or Subcollection size:
175 size <- arvadosFile$getSizeInBytes()
181 size <- arvadosSubcollection$getSizeInBytes()
184 * Create new file in a collection:
187 collection$create(fileNames, optionalRelativePath)
193 mainFile <- collection$create("main.cpp", "cpp/src/")
194 fileList <- collection$create(c("main.cpp", lib.dll), "cpp/src/")
197 * Add existing ArvadosFile or Subcollection to a collection:
200 folder <- Subcollection$new("src")
201 file <- ArvadosFile$new("main.cpp")
206 collection$add(folder, "cpp")
209 This examples will add file "main.cpp" in "./cpp/src/" folder if folder exists.
210 If subcollection contains more files or folders they will be added recursively.
212 * Delete file from a collection:
215 collection$remove("location/to/my/file.cpp")
218 You can remove both Subcollection and ArvadosFile.
219 If subcollection contains more files or folders they will be removed recursively.
221 You can also remove multiple files at once:
224 collection$remove(c("path/to/my/file.cpp", "path/to/other/file.cpp"))
227 * Delete file or folder from a Subcollection:
230 subcollection <- collection$get("mySubcollection/")
231 subcollection$remove("fileInsideSubcollection.exe")
232 subcollection$remove("folderInsideSubcollection/")
235 * Move file or folder inside collection:
237 Directley from collection
240 collection$move("folder/file.cpp", "file.cpp")
246 file <- collection$get("location/to/my/file.cpp")
247 file$move("newDestination/file.cpp")
250 Or from subcollection
253 subcollection <- collection$get("location/to/folder")
254 subcollection$move("newDestination/folder")
257 Make sure to include new file name in destination.
258 In second example file$move("newDestination/") will not work.
260 #### Working with Aravdos projects
265 project <- arv$projects.get("uuid")
271 list subprojects of a project
272 projects <- arv$projects.list(list(list("owner_uuid", "=", "aaaaa-j7d0g-ccccccccccccccc")))
274 list projects which have names beginning with Example
275 examples <- arv$projects.list(list(list("name","like","Example%")))
278 * List all projects even if the number of items is greater than maximum API limit:
281 projects <- listAll(arv$projects.list, list(list("name","like","Example%")))
287 deletedProject <- arv$projects.delete("uuid")
293 updatedProject <- arv$projects.update(list(name = "new_name", description = "new description"), "uuid")
299 newProject <- arv$projects.update(list(name = "project_name", description = "project description"))
304 * View help page of Arvados classes by puting ? before class name:
313 * View help page of any method defined in Arvados class by puting ? before method name:
320 ### Building the ArvadosR package
323 cd arvados/sdk && R CMD build R
326 This will create a tarball of the ArvadosR package in the current directory.