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. The API is not final and feedback is solicited from users on ways in which it could be improved.
13 * Working with collections
14 * Manipulating collection content
15 * Working with Arvados projects
17 * Building the ArvadosR package
21 Minimum R version required to run ArvadosR is 3.3.0.
24 install.packages("ArvadosR", repos=c("https://r.arvados.org", getOption("repos")["CRAN"]), dependencies=TRUE)
29 > On Linux, you may have to install supporting packages.
31 > On Centos 7, this is:
33 > yum install libxml2-devel openssl-devel curl-devel
38 > apt-get install build-essential libxml2-dev libssl-dev libcurl4-gnutls-dev
47 # use environment variables ARVADOS_API_TOKEN and ARVADOS_API_HOST
50 # provide them explicitly
51 arv <- Arvados$new("your Arvados token", "example.arvadosapi.com")
54 Optionally, add `numRetries` parameter to specify number of times to retry failed service requests. Default is 0.
57 arv <- Arvados$new("your Arvados token", "example.arvadosapi.com", numRetries = 3)
60 This parameter can be set at any time using `setNumRetries`
66 ### Working with collections
68 #### Get a collection:
71 collection <- arv$collections_get("uuid")
74 Be aware that the result from `collections_get` is not a Collection class. The object returned from this method lets you access collection fields like “name” and “description”. The Collection class lets you access the files in the collection for reading and writing, and is described in the next section.
76 #### List collections:
79 # offset of 0 and default limit of 100
80 collectionList <- arv$collections_list(list(list("name", "like", "Test%")))
82 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 collection <- arv$collections_update(name = "newCollectionTitle", description = "newCollectionDescription", ownerUUID = "collectionOwner", properties = NULL, uuid = "collectionUUID")
109 #### Create a new collection:
112 newCollection <- arv$collections_create(name = "collectionTitle", description = "collectionDescription", ownerUUID = "collectionOwner", properties = Properties)
115 ### Manipulating collection content
117 #### Initialize a collection object:
120 collection <- Collection$new(arv, "uuid")
123 #### Get list of files:
126 files <- collection$getFileListing()
129 #### Get ArvadosFile or Subcollection from internal tree-like structure:
132 arvadosFile <- collection$get("location/to/my/file.cpp")
134 arvadosSubcollection <- collection$get("location/to/my/directory/")
140 arvadosFile <- collection$get("myinput.txt")
141 arvConnection <- arvadosFile$connection("r")
142 mytable <- read.table(arvConnection)
148 arvadosFile <- collection$create("myoutput.txt")[[1]]
149 arvConnection <- arvadosFile$connection("w")
150 write.table(mytable, arvConnection)
154 #### Read a table from a tab delimited file:
157 arvadosFile <- collection$get("myinput.txt")
158 arvConnection <- arvadosFile$connection("r")
159 mytable <- read.delim(arvConnection)
162 #### Read a gzip compressed R object:
165 obj <- readRDS(gzcon(coll$get("abc.RDS")$connection("rb")))
168 #### Write to existing file (overwrites current content of the file):
171 arvadosFile <- collection$get("location/to/my/file.cpp")
172 arvadosFile$write("This is new file content")
175 #### Read whole file or just a portion of it:
178 fileContent <- arvadosFile$read()
179 fileContent <- arvadosFile$read("text")
180 fileContent <- arvadosFile$read("raw", offset = 1024, length = 512)
183 #### Read various file types:
185 Chooses file type based on file name extension. Recognized file extensions: 'txt', 'xlsx', 'csv', 'tsv', 'fasta', 'dat', 'bin', 'rds', 'rdata'.
188 collection <- Collection$new(arv, collectionUUID)
189 readFile <- collection$readArvFile(arvadosFile, istable = 'yes') # table
190 readFile <- collection$readArvFile(arvadosFile, istable = 'no') # text
191 readFile <- collection$readArvFile(arvadosFile) # xlsx, csv, tsv, rds, rdata
192 readFile <- collection$readArvFile(arvadosFile, fileclass = 'fasta') # fasta
193 readFile <- collection$readArvFile(arvadosFile, Ncol= 4, Nrow = 32) # binary data.frame, only numbers
194 readFile <- collection$readArvFile(arvadosFile, Ncol = 5, Nrow = 150, istable = "factor") # binary data.frame with factor or text
197 #### Get ArvadosFile or Subcollection size:
200 size <- arvadosFile$getSizeInBytes()
202 size <- arvadosSubcollection$getSizeInBytes()
205 #### Create new file in a collection (returns a vector of one or more ArvadosFile objects):
208 collection$create(files)
214 mainFile <- collection$create("cpp/src/main.cpp")[[1]]
215 fileList <- collection$create(c("cpp/src/main.cpp", "cpp/src/util.h"))
218 #### Delete file from a collection:
221 collection$remove("location/to/my/file.cpp")
224 You can remove both Subcollection and ArvadosFile. If subcollection contains more files or folders they will be removed recursively.
227 > You can also remove multiple files at once:
229 > collection$remove(c("path/to/my/file.cpp", "path/to/other/file.cpp"))
232 #### Delete file or folder from a Subcollection:
235 subcollection <- collection$get("mySubcollection/")
236 subcollection$remove("fileInsideSubcollection.exe")
237 subcollection$remove("folderInsideSubcollection/")
240 #### Move or rename a file or folder within a collection (moving between collections is currently not supported):
242 ##### Directly from collection
245 collection$move("folder/file.cpp", "file.cpp")
251 file <- collection$get("location/to/my/file.cpp")
252 file$move("newDestination/file.cpp")
255 ##### Or from subcollection
258 subcollection <- collection$get("location/to/folder")
259 subcollection$move("newDestination/folder")
263 > Make sure to include new file name in destination. In second example `file$move(“newDestination/”)` will not work.
265 #### Copy file or folder within a collection (copying between collections is currently not supported):
267 ##### Directly from collection
270 collection$copy("folder/file.cpp", "file.cpp")
276 file <- collection$get("location/to/my/file.cpp")
277 file$copy("destination/file.cpp")
280 ##### Or from subcollection
283 subcollection <- collection$get("location/to/folder")
284 subcollection$copy("destination/folder")
287 ### Working with Aravdos projects
292 project <- arv$project_get("uuid")
298 list subprojects of a project
299 projects <- arv$project_list(list(list("owner_uuid", "=", "aaaaa-j7d0g-ccccccccccccccc")))
301 list projects which have names beginning with Example
302 examples <- arv$project_list(list(list("name","like","Example%")))
305 #### List all projects even if the number of items is greater than maximum API limit:
308 projects <- listAll(arv$project_list, list(list("name","like","Example%")))
311 ##### Delete a project:
314 deletedProject <- arv$project_delete("uuid")
317 ##### Update project:
320 updatedProject <- arv$project_update(name = "new project name", properties = newProperties, uuid = "projectUUID")
323 ##### Create project:
326 newProject <- arv$project_create(name = "project name", description = "project description", owner_uuid = "project UUID", properties = NULL, ensureUniqueName = "false")
331 #### View help page of Arvados classes by puting `?` before class name:
340 #### View help page of any method defined in Arvados class by puting `?` before method name:
347 <!-- Taka konwencja USAGE -->
349 ## Building the ArvadosR package
352 cd arvados/sdk && R CMD build R
355 This will create a tarball of the ArvadosR package in the current directory.
357 <!-- Czy dodawać Documentation / Community / Development and Contributing / Licensing? Ale tylko do części Rowej? Wszystko? Wcale? -->
361 Complete documentation, including the [User Guide](https://doc.arvados.org/user/index.html), [Installation documentation](https://doc.arvados.org/install/index.html), [Administrator documentation](https://doc.arvados.org/admin/index.html) and
362 [API documentation](https://doc.arvados.org/api/index.html) is available at http://doc.arvados.org/
366 Visit [Arvados Community and Getting Help](https://doc.arvados.org/user/getting_started/community.html).
370 [Report a bug](https://dev.arvados.org/projects/arvados/issues/new) on [dev.arvados.org](https://dev.arvados.org).
374 Arvados is Free Software. See [Arvados Free Software Licenses](https://doc.arvados.org/user/copying/copying.html) for information about the open source licenses used in Arvados.