3 This SDK focuses on providing support for accessing Arvados projects, collections, and the files within collections.
4 The API is not final and feedback is solicited from users on ways in which it could be improved.
9 knitr::opts_chunk$set(eval=FALSE)
13 install.packages("ArvadosR", repos=c("http://r.arvados.org", getOption("repos")["CRAN"]), dependencies=TRUE)
16 Note: on Linux, you may have to install supporting packages.
21 yum install libxml2-devel openssl-devel curl-devel
27 apt-get install build-essential libxml2-dev libssl-dev libcurl4-gnutls-dev
35 * Load Library and Initialize API:
39 # use environment variables ARVADOS_API_TOKEN and ARVADOS_API_HOST
42 # provide them explicitly
43 arv <- Arvados$new("your Arvados token", "example.arvadosapi.com")
46 Optionally, add numRetries parameter to specify number of times to retry failed service requests.
50 arv <- Arvados$new("your Arvados token", "example.arvadosapi.com", numRetries = 3)
53 This parameter can be set at any time using setNumRetries
60 #### Working with collections
65 collection <- arv$collections.get("uuid")
71 # offset of 0 and default limit of 100
72 collectionList <- arv$collections.list(list(list("name", "like", "Test%")))
74 collectionList <- arv$collections.list(list(list("name", "like", "Test%")), limit = 10, offset = 2)
78 # count of total number of items (may be more than returned due to paging)
79 collectionList$items_available
81 # items which match the filter criteria
85 * List all collections even if the number of items is greater than maximum API limit:
88 collectionList <- listAll(arv$collections.list, list(list("name", "like", "Test%")))
91 * Delete a collection:
94 deletedCollection <- arv$collections.delete("uuid")
97 * Update a collection's metadata:
100 updatedCollection <- arv$collections.update(list(name = "New name", description = "New description"), "uuid")
106 newCollection <- arv$collections.create(list(name = "Example", description = "This is a test collection"))
110 #### Manipulating collection content
112 * Create collection object:
115 collection <- Collection$new(arv, "uuid")
121 files <- collection$getFileListing()
124 * Get ArvadosFile or Subcollection from internal tree-like structure:
127 arvadosFile <- collection$get("location/to/my/file.cpp")
133 arvadosSubcollection <- collection$get("location/to/my/directory/")
139 arvadosFile <- collection$get("myinput.txt")
140 arvConnection <- arvadosFile$connection("r")
141 mytable <- read.table(arvConnection)
147 arvadosFile <- collection$create("myoutput.txt")
148 arvConnection <- arvadosFile$connection("w")
149 write.table(mytable, arvConnection)
153 * Write to existing file (override current content of the file):
156 arvadosFile <- collection$get("location/to/my/file.cpp")
157 arvadosFile$write("This is new file content")
160 * Read whole file or just a portion of it:
163 fileContent <- arvadosFile$read()
164 fileContent <- arvadosFile$read("text")
165 fileContent <- arvadosFile$read("raw", offset = 1024, length = 512)
168 * Get ArvadosFile or Subcollection size:
171 size <- arvadosFile$getSizeInBytes()
177 size <- arvadosSubcollection$getSizeInBytes()
180 * Create new file in a collection:
183 collection$create(fileNames, optionalRelativePath)
189 mainFile <- collection$create("main.cpp", "cpp/src/")
190 fileList <- collection$create(c("main.cpp", lib.dll), "cpp/src/")
193 * Add existing ArvadosFile or Subcollection to a collection:
196 folder <- Subcollection$new("src")
197 file <- ArvadosFile$new("main.cpp")
202 collection$add(folder, "cpp")
205 This examples will add file "main.cpp" in "./cpp/src/" folder if folder exists.
206 If subcollection contains more files or folders they will be added recursively.
208 * Delete file from a collection:
211 collection$remove("location/to/my/file.cpp")
214 You can remove both Subcollection and ArvadosFile.
215 If subcollection contains more files or folders they will be removed recursively.
217 You can also remove multiple files at once:
220 collection$remove(c("path/to/my/file.cpp", "path/to/other/file.cpp"))
223 * Delete file or folder from a Subcollection:
226 subcollection <- collection$get("mySubcollection/")
227 subcollection$remove("fileInsideSubcollection.exe")
228 subcollection$remove("folderInsideSubcollection/")
231 * Move file or folder inside collection:
233 Directley from collection
236 collection$move("folder/file.cpp", "file.cpp")
242 file <- collection$get("location/to/my/file.cpp")
243 file$move("newDestination/file.cpp")
246 Or from subcollection
249 subcollection <- collection$get("location/to/folder")
250 subcollection$move("newDestination/folder")
253 Make sure to include new file name in destination.
254 In second example file$move("newDestination/") will not work.
256 #### Working with Aravdos projects
261 project <- arv$projects.get("uuid")
267 list subprojects of a project
268 projects <- arv$projects.list(list(list("owner_uuid", "=", "aaaaa-j7d0g-ccccccccccccccc")))
270 list projects which have names beginning with Example
271 examples <- arv$projects.list(list(list("name","like","Example%")))
274 * List all projects even if the number of items is greater than maximum API limit:
277 projects <- listAll(arv$projects.list, list(list("name","like","Example%")))
283 deletedProject <- arv$projects.delete("uuid")
289 updatedProject <- arv$projects.update(list(name = "new_name", description = "new description"), "uuid")
295 newProject <- arv$projects.update(list(name = "project_name", description = "project description"))
300 * View help page of Arvados classes by puting ? before class name:
309 * View help page of any method defined in Arvados class by puting ? before method name:
316 ### Building the ArvadosR package
319 cd arvados/sdk && R CMD build R
322 This will create a tarball of the ArvadosR package in the current directory.