5ae23c2acca73814caa51e32c7bd62aa8fcefb1f
[arvados.git] / sdk / R / README
1 R SDK for Arvados
2
3 Installation from source
4
5 1. Dependencies
6
7 libxml2-dev, libssl-dev, curl
8
9 2. Build the ArvadosR package tarball
10
11 cd arvados/sdk
12 R CMD build R
13
14 That will create a tarball of the Arvados package in the current directory.
15
16 3. Install the R package and its dependencies
17
18 Then start R. Assuming the generated tarball is named `ArvadosR_0.0.1.tar.gz`,
19 install it like this:
20
21 > install.packages(c('R6', 'httr', 'stringr', 'jsonlite', 'curl', 'XML'))
22 > install.packages('./ArvadosR_0.0.1.tar.gz', repos = NULL, type="source", dependencies = TRUE)
23 > library('ArvadosR')
24
25 4. Examples of usage:
26
27 --------------------------------------------------------------------------------------------------------------------------------
28
29 #Initialize API:
30
31 arv <- Arvados$new("insert_token", "insert_host_name")
32
33 --------------------------------------------------------------------------------------------------------------------------------
34
35 #Get collection:
36
37 arv$getCollection("uuid")
38
39 --------------------------------------------------------------------------------------------------------------------------------
40
41 #List collections:
42 collectionList <- arv$listCollections(list(list("uuid", "=", "aaaaa-4zz18-ccccccccccccccc")), limit = 10, offset = 2)
43
44 --------------------------------------------------------------------------------------------------------------------------------
45
46 #Delete collection:
47
48 deletedCollection <- arv$deleteCollection("uuid")
49
50 --------------------------------------------------------------------------------------------------------------------------------
51
52 #Update collection:
53
54 updatedCollection <- arv$updateCollection("uuid", list(list(name = "new_name", description = "new_desciption")))
55
56 --------------------------------------------------------------------------------------------------------------------------------
57
58 #Create collection:
59
60 createdCollection <- arv$createCollection(list(list(name = "new_name", description = "new_desciption")))
61
62 --------------------------------------------------------------------------------------------------------------------------------
63
64 --------------------------------------------------------------------------------------------------------------------------------
65
66 #Collection content manipulation:
67
68 --------------------------------------------------------------------------------------------------------------------------------
69
70 --------------------------------------------------------------------------------------------------------------------------------
71
72 #Create collection object:
73
74 collection <- Collection$new(arv, "uuid")
75
76 --------------------------------------------------------------------------------------------------------------------------------
77
78 #Get file/folder content as character vector
79
80 collection$getFileContent()
81
82 --------------------------------------------------------------------------------------------------------------------------------
83
84 #This will return ArvadosFile or Subcollection from internal tree-like structure.
85
86 arvadosFile <- collection$get("location/to/my/file.cpp")
87
88 #or
89
90 arvadosSubcollection <- collection$get("location/to/my/directory/")
91
92 --------------------------------------------------------------------------------------------------------------------------------
93
94 #Read whole file or just a portion of it.
95
96 fileContent <- arvadosFile$read()
97 fileContent <- arvadosFile$read("text")
98 fileContent <- arvadosFile$read("raw", offset = 1024, length = 512)
99
100 --------------------------------------------------------------------------------------------------------------------------------
101
102 #Get ArvadosFile or Subcollection size 
103
104 size <- arvadosFile$getSizeInBytes()
105 size <- arvadosSubcollection$getSizeInBytes()
106
107 --------------------------------------------------------------------------------------------------------------------------------
108
109 #Create new file in a collection
110
111 #Call structure
112
113 collection$add(arvadosFileOrSubcollectionOrFileName, optionalRelativePath)
114
115 #Example
116
117 collection$add("main.cpp", "cpp/src/")
118
119 #or
120
121 folder <- Subcollection$new("src")
122 file <- ArvadosFile$new("main.cpp")
123 folder$add(file)
124
125 collection$add(folder, "cpp")
126
127 #Both examples will add file "main.cpp" in "./cpp/src/" folder if folder exists.
128 #If subcollection contains more files or folders they will be added recursively.
129
130 #You can also add multiple files
131
132 collection$add(c("path/to/my/file.cpp", "path/to/other/file.cpp"))
133
134 --------------------------------------------------------------------------------------------------------------------------------
135
136 #Write to existing file (Override current content of the file)
137
138 arvadosFile <- collection$get("location/to/my/file.cpp")
139
140 arvadosFile$write("This is new file content")
141
142 --------------------------------------------------------------------------------------------------------------------------------
143
144 #Delete file from a collection
145
146 file <- collection$get("location/to/my/file.cpp")
147
148 file$removeFromCollection()
149
150 #Or
151
152 collection$remove(file)
153
154 #Both examples will remove file "file.cpp" from a collection
155 #If subcollection contains more files or folders they will be removed recursively.
156
157 #You can also remove multiple files
158
159 collection$remove(c("path/to/my/file.cpp", "path/to/other/file.cpp"))
160
161 --------------------------------------------------------------------------------------------------------------------------------
162
163 #Move file or folder inside collection
164
165 file <- collection$get("location/to/my/file.cpp")
166
167 file$move("destination/file.cpp")
168
169 #Or subcollections
170
171 subcollection <- collection$get("location/to/folder")
172
173 subcollection$move("destination/folder")
174
175 #Make sure to include folder name in destination
176 #For example
177 #file$move("destination/") will not work
178
179 --------------------------------------------------------------------------------------------------------------------------------
180
181 --------------------------------------------------------------------------------------------------------------------------------
182
183 # Working with projects:
184
185 #Get project:
186
187 arv$getProject("uuid")
188
189 --------------------------------------------------------------------------------------------------------------------------------
190
191 #List projects:
192 projects <- arv$listProjects(list(list("uuid", "=", "aaaaa-j7d0g-ccccccccccccccc")), limit = 10, offset = 2)
193
194 --------------------------------------------------------------------------------------------------------------------------------
195
196 #Delete project:
197
198 deletedProject <- arv$deleteProject("uuid")
199
200 --------------------------------------------------------------------------------------------------------------------------------
201
202 #Update project:
203
204 updatedProject <- arv$updateProject("uuid", list(list(name = "new_name", description = "new_desciption")))
205
206 --------------------------------------------------------------------------------------------------------------------------------
207
208 #Create project:
209
210 createdProject <- arv$createProject(list(list(name = "project_name", description = "project_desciption")))
211
212 --------------------------------------------------------------------------------------------------------------------------------