Implemented custom print functions for all public classes
[arvados.git] / sdk / R / README
1 R SDK for Arvados
2
3 This SDK focuses on providing support for accessing Arvados projects, collections, and the files within collections.
4
5 The API is not final and feedback is solicited from users on ways in which it could be improved.
6
7 INSTALLATION
8
9 1. Install the dependencies
10
11     > install.packages(c('R6', 'httr', 'stringr', 'jsonlite', 'curl', 'XML'))
12
13 If needed, you may have to install the supporting packages first. On Linux, these are:
14
15     libxml2-dev, libssl-dev, libcurl4-gnutls-dev or libcurl4-openssl-dev
16
17 2. Install the ArvardosR package
18
19     > install.packages('/path/to/ArvadosR_0.0.2.tar.gz', repos = NULL, type="source", dependencies = TRUE)
20
21
22 EXAMPLES OF USAGE
23
24
25 #Load Library and Initialize API:
26
27 library('ArvadosR')
28 arv <- Arvados$new() # uses environment variables ARVADOS_API_TOKEN and ARVADOS_API_HOST
29 arv <- Arvados$new("your Arvados token", "example.arvadosapi.com")
30
31 --------------------------------------------------------------------------------------------------------------------------------
32
33 #Get a collection:
34
35 arv$getCollection("uuid")
36
37 --------------------------------------------------------------------------------------------------------------------------------
38
39 #List collections:
40 collectionList <- arv$listCollections(list(list("name", "like", "Test%"))) # offset of 0 and default limit of 100
41 collectionList <- arv$listCollections(list(list("name", "like", "Test%")), limit = 10, offset = 2)
42
43 collectionList$items_available # count of total number of items (may be more than returned due to paging)
44 collectionList$items # items which match the filter criteria
45
46 #Next example will list all collections even when the number of items is greater than maximum API limit
47
48 collectionList <- arv$listAllCollections(list(list("name", "like", "Test%")))
49
50 --------------------------------------------------------------------------------------------------------------------------------
51
52 #Delete a collection:
53
54 deletedCollection <- arv$deleteCollection("uuid")
55
56 --------------------------------------------------------------------------------------------------------------------------------
57
58 #Update a collection's metadata:
59
60 updatedCollection <- arv$updateCollection("uuid", list(name = "New name", description = "New description"))
61
62 --------------------------------------------------------------------------------------------------------------------------------
63
64 #Create collection:
65
66 createdCollection <- arv$createCollection(list(name = "Example", description = "This is a test collection"))
67
68
69 --------------------------------------------------------------------------------------------------------------------------------
70 COLLECTION CONTENT MANIPULATION
71 --------------------------------------------------------------------------------------------------------------------------------
72
73 #Create collection object:
74
75 collection <- Collection$new(arv, "uuid")
76
77 --------------------------------------------------------------------------------------------------------------------------------
78
79 #Get list of files
80
81 collection$getFileListing()
82
83 --------------------------------------------------------------------------------------------------------------------------------
84
85 #This will return ArvadosFile or Subcollection from internal tree-like structure.
86
87 arvadosFile <- collection$get("location/to/my/file.cpp")
88
89 #or
90
91 arvadosSubcollection <- collection$get("location/to/my/directory/")
92
93 --------------------------------------------------------------------------------------------------------------------------------
94
95 #Read a table
96
97 arvadosFile   <- collection$get("myinput.txt")
98 arvConnection <- arvadosFile$connection("r")
99 mytable       <- read.table(arvConnection)
100
101 #Write a table
102
103 arvadosFile   <- collection$create("myoutput.txt")
104 arvConnection <- arvadosFile$connection("w")
105 write.table(mytable, arvConnection)
106 arvadosFile$flush()
107
108 --------------------------------------------------------------------------------------------------------------------------------
109
110 #Read whole file or just a portion of it.
111
112 fileContent <- arvadosFile$read()
113 fileContent <- arvadosFile$read("text")
114 fileContent <- arvadosFile$read("raw", offset = 1024, length = 512)
115
116 --------------------------------------------------------------------------------------------------------------------------------
117
118 #Get ArvadosFile or Subcollection size
119
120 size <- arvadosFile$getSizeInBytes()
121 size <- arvadosSubcollection$getSizeInBytes()
122
123 --------------------------------------------------------------------------------------------------------------------------------
124
125 #Create new file in a collection
126
127 collection$create(fileNames, optionalRelativePath)
128
129 #Example
130
131 mainFile <- collection$create("main.cpp", "cpp/src/")
132 fileList <- collection$create(c("main.cpp", lib.dll), "cpp/src/")
133
134 --------------------------------------------------------------------------------------------------------------------------------
135
136 #Add existing ArvadosFile or Subcollection to a collection
137
138 folder <- Subcollection$new("src")
139 file   <- ArvadosFile$new("main.cpp")
140 folder$add(file)
141
142 collection$add(folder, "cpp")
143
144 #This examples will add file "main.cpp" in "./cpp/src/" folder if folder exists.
145 #If subcollection contains more files or folders they will be added recursively.
146
147 --------------------------------------------------------------------------------------------------------------------------------
148
149 #Write to existing file (Override current content of the file)
150
151 arvadosFile <- collection$get("location/to/my/file.cpp")
152
153 arvadosFile$write("This is new file content")
154
155 --------------------------------------------------------------------------------------------------------------------------------
156
157 #Delete file from a collection
158
159 collection$remove("location/to/my/file.cpp")
160
161 #You can remove both Subcollection and ArvadosFile
162 #If subcollection contains more files or folders they will be removed recursively.
163
164 #You can also remove multiple files
165
166 collection$remove(c("path/to/my/file.cpp", "path/to/other/file.cpp"))
167
168 #Delete file or folder from a Subcollection
169
170 subcollection <- collection$get("mySubcollection/")
171 subcollection$remove("fileInsideSubcollection.exe")
172 subcollection$remove("folderInsideSubcollection/")
173
174 --------------------------------------------------------------------------------------------------------------------------------
175
176 #Move file or folder inside collection
177
178 #Directley from collection
179
180 collection$move("folder/file.cpp", "file.cpp")
181
182 #Or from file
183
184 file <- collection$get("location/to/my/file.cpp")
185 file$move("newDestination/file.cpp")
186
187 #Or from subcollection
188
189 subcollection <- collection$get("location/to/folder")
190 subcollection$move("newDestination/folder")
191
192 #Make sure to include new file name in destination
193 #In second example file$move("newDestination/") will not work
194
195 --------------------------------------------------------------------------------------------------------------------------------
196 WORKING WITH ARVADOS PROJECTS
197 --------------------------------------------------------------------------------------------------------------------------------
198
199 #Get a project:
200
201 arv$getProject("uuid")
202
203 --------------------------------------------------------------------------------------------------------------------------------
204
205 #List projects:
206
207 projects <- arv$listProjects(list(list("owner_uuid", "=", "aaaaa-j7d0g-ccccccccccccccc"))) # list subprojects of a project
208 arv$listProjects(list(list("name","like","Example%"))) # list projects which have names beginning with Example
209
210 #Next example will list all projects even when the number of items is greater than maximum API limit
211
212 collectionList <- arv$listAllProjects(list(list("name","like","Example%")))
213
214 --------------------------------------------------------------------------------------------------------------------------------
215
216 #Delete a project:
217
218 deletedProject <- arv$deleteProject("uuid")
219
220 --------------------------------------------------------------------------------------------------------------------------------
221
222 #Update project:
223
224 updatedProject <- arv$updateProject("uuid", list(name = "new_name", description = "new description"))
225
226 --------------------------------------------------------------------------------------------------------------------------------
227
228 #Create project:
229
230 createdProject <- arv$createProject(list(name = "project_name", description = "project description"))
231
232
233 --------------------------------------------------------------------------------------------------------------------------------
234 BUILDING THE ARVADOS SDK TARBALL
235 --------------------------------------------------------------------------------------------------------------------------------
236
237
238 cd arvados/sdk
239 R CMD build R
240
241 This will create a tarball of the Arvados package in the current directory.