3 This SDK focuses on providing support for accessing Arvados projects, collections, and the files within collections.
5 The API is not final and feedback is solicited from users on ways in which it could be improved.
9 1. Install the dependencies
11 > install.packages(c('R6', 'httr', 'stringr', 'jsonlite', 'curl', 'XML'))
13 If needed, you may have to install the supporting packages first. On Linux, these are:
15 libxml2-dev, libssl-dev, libcurl4-gnutls-dev or libcurl4-openssl-dev
17 2. Install the ArvardosR package
19 > install.packages('/path/to/ArvadosR_0.0.2.tar.gz', repos = NULL, type="source", dependencies = TRUE)
25 #Load Library and Initialize API:
28 arv <- Arvados$new() # uses environment variables ARVADOS_API_TOKEN and ARVADOS_API_HOST
29 arv <- Arvados$new("your Arvados token", "example.arvadosapi.com")
32 #Optionally, add numRetries parameter to specify number of times to retry failed service requests.
35 arv <- Arvados$new("your Arvados token", "example.arvadosapi.com", numRetries = 3)
37 #This parameter can be set at any time using setNumRetries
41 --------------------------------------------------------------------------------------------------------------------------------
45 arv$getCollection("uuid")
47 --------------------------------------------------------------------------------------------------------------------------------
50 collectionList <- arv$listCollections(list(list("name", "like", "Test%"))) # offset of 0 and default limit of 100
51 collectionList <- arv$listCollections(list(list("name", "like", "Test%")), limit = 10, offset = 2)
53 collectionList$items_available # count of total number of items (may be more than returned due to paging)
54 collectionList$items # items which match the filter criteria
56 #Next example will list all collections even when the number of items is greater than maximum API limit
58 collectionList <- arv$listAllCollections(list(list("name", "like", "Test%")))
60 --------------------------------------------------------------------------------------------------------------------------------
64 deletedCollection <- arv$deleteCollection("uuid")
66 --------------------------------------------------------------------------------------------------------------------------------
68 #Update a collection's metadata:
70 updatedCollection <- arv$updateCollection("uuid", list(name = "New name", description = "New description"))
72 --------------------------------------------------------------------------------------------------------------------------------
76 createdCollection <- arv$createCollection(list(name = "Example", description = "This is a test collection"))
79 --------------------------------------------------------------------------------------------------------------------------------
80 COLLECTION CONTENT MANIPULATION
81 --------------------------------------------------------------------------------------------------------------------------------
83 #Create collection object:
85 collection <- Collection$new(arv, "uuid")
87 --------------------------------------------------------------------------------------------------------------------------------
91 collection$getFileListing()
93 --------------------------------------------------------------------------------------------------------------------------------
95 #This will return ArvadosFile or Subcollection from internal tree-like structure.
97 arvadosFile <- collection$get("location/to/my/file.cpp")
101 arvadosSubcollection <- collection$get("location/to/my/directory/")
103 --------------------------------------------------------------------------------------------------------------------------------
107 arvadosFile <- collection$get("myinput.txt")
108 arvConnection <- arvadosFile$connection("r")
109 mytable <- read.table(arvConnection)
113 arvadosFile <- collection$create("myoutput.txt")
114 arvConnection <- arvadosFile$connection("w")
115 write.table(mytable, arvConnection)
118 --------------------------------------------------------------------------------------------------------------------------------
120 #Read whole file or just a portion of it.
122 fileContent <- arvadosFile$read()
123 fileContent <- arvadosFile$read("text")
124 fileContent <- arvadosFile$read("raw", offset = 1024, length = 512)
126 --------------------------------------------------------------------------------------------------------------------------------
128 #Get ArvadosFile or Subcollection size
130 size <- arvadosFile$getSizeInBytes()
131 size <- arvadosSubcollection$getSizeInBytes()
133 --------------------------------------------------------------------------------------------------------------------------------
135 #Create new file in a collection
137 collection$create(fileNames, optionalRelativePath)
141 mainFile <- collection$create("main.cpp", "cpp/src/")
142 fileList <- collection$create(c("main.cpp", lib.dll), "cpp/src/")
144 --------------------------------------------------------------------------------------------------------------------------------
146 #Add existing ArvadosFile or Subcollection to a collection
148 folder <- Subcollection$new("src")
149 file <- ArvadosFile$new("main.cpp")
152 collection$add(folder, "cpp")
154 #This examples will add file "main.cpp" in "./cpp/src/" folder if folder exists.
155 #If subcollection contains more files or folders they will be added recursively.
157 --------------------------------------------------------------------------------------------------------------------------------
159 #Write to existing file (Override current content of the file)
161 arvadosFile <- collection$get("location/to/my/file.cpp")
163 arvadosFile$write("This is new file content")
165 --------------------------------------------------------------------------------------------------------------------------------
167 #Delete file from a collection
169 collection$remove("location/to/my/file.cpp")
171 #You can remove both Subcollection and ArvadosFile
172 #If subcollection contains more files or folders they will be removed recursively.
174 #You can also remove multiple files
176 collection$remove(c("path/to/my/file.cpp", "path/to/other/file.cpp"))
178 #Delete file or folder from a Subcollection
180 subcollection <- collection$get("mySubcollection/")
181 subcollection$remove("fileInsideSubcollection.exe")
182 subcollection$remove("folderInsideSubcollection/")
184 --------------------------------------------------------------------------------------------------------------------------------
186 #Move file or folder inside collection
188 #Directley from collection
190 collection$move("folder/file.cpp", "file.cpp")
194 file <- collection$get("location/to/my/file.cpp")
195 file$move("newDestination/file.cpp")
197 #Or from subcollection
199 subcollection <- collection$get("location/to/folder")
200 subcollection$move("newDestination/folder")
202 #Make sure to include new file name in destination
203 #In second example file$move("newDestination/") will not work
205 --------------------------------------------------------------------------------------------------------------------------------
206 WORKING WITH ARVADOS PROJECTS
207 --------------------------------------------------------------------------------------------------------------------------------
211 arv$getProject("uuid")
213 --------------------------------------------------------------------------------------------------------------------------------
217 projects <- arv$listProjects(list(list("owner_uuid", "=", "aaaaa-j7d0g-ccccccccccccccc"))) # list subprojects of a project
218 arv$listProjects(list(list("name","like","Example%"))) # list projects which have names beginning with Example
220 #Next example will list all projects even when the number of items is greater than maximum API limit
222 collectionList <- arv$listAllProjects(list(list("name","like","Example%")))
224 --------------------------------------------------------------------------------------------------------------------------------
228 deletedProject <- arv$deleteProject("uuid")
230 --------------------------------------------------------------------------------------------------------------------------------
234 updatedProject <- arv$updateProject("uuid", list(name = "new_name", description = "new description"))
236 --------------------------------------------------------------------------------------------------------------------------------
240 createdProject <- arv$createProject(list(name = "project_name", description = "project description"))
243 --------------------------------------------------------------------------------------------------------------------------------
244 BUILDING THE ARVADOS SDK TARBALL
245 --------------------------------------------------------------------------------------------------------------------------------
251 This will create a tarball of the Arvados package in the current directory.