Merge branch 'master' of git.curoverse.com:arvados into 11876-r-sdk
[arvados.git] / sdk / R / README
1 R SDK for Arvados
2
3 Examples of usage:
4
5 --------------------------------------------------------------------------------------------------------------------------------
6
7 #Initialize API:
8
9 arv <- Arvados$new("insert_token", "insert_host_name")
10
11 --------------------------------------------------------------------------------------------------------------------------------
12
13 #Get collection:
14
15 arv$getCollection("uuid")
16
17 --------------------------------------------------------------------------------------------------------------------------------
18
19 #List collections:
20
21 collectionList <- arv$listCollections(list("uuid", "=" "aaaaa-bbbbb-ccccccccccccccc"), limit = 10, offset = 2)
22
23 --------------------------------------------------------------------------------------------------------------------------------
24
25 #Delete collection:
26
27 deletedCollection <- arv$deleteCollection("uuid")
28
29 --------------------------------------------------------------------------------------------------------------------------------
30
31 #Update collection:
32
33 updatedCollection <- arv$updateCollection("uuid", list((name = "new_name", description = "new_desciption")))
34
35 --------------------------------------------------------------------------------------------------------------------------------
36
37 #Create collection:
38
39 cratedCollection <- arv$createCollection(list(list(name = "new_name", description = "new_desciption")))
40
41 --------------------------------------------------------------------------------------------------------------------------------
42
43 --------------------------------------------------------------------------------------------------------------------------------
44
45 #Collection content manipulation:
46
47 --------------------------------------------------------------------------------------------------------------------------------
48
49 --------------------------------------------------------------------------------------------------------------------------------
50
51 #Create collection object:
52
53 arv <- Arvados$new("insert_token", "insert_host_name")
54 collection <- Collection$new(arv, "uuid")
55
56 --------------------------------------------------------------------------------------------------------------------------------
57
58 #Get file/folder content as character vector
59
60 collection$getFileContent()
61
62 --------------------------------------------------------------------------------------------------------------------------------
63
64 #This will return ArvadosFile or Subcollection from internal tree-like structure.
65
66 arvadosFile <- collection$get("location/to/my/file.cpp")
67
68 #or
69
70 arvadosSubcollection <- collection$get("location/to/my/directory/")
71
72 --------------------------------------------------------------------------------------------------------------------------------
73
74 #Read whole file or just a portion of it.
75
76 fileContent <- arvadosFile$read(offset = 1024, length = 512)
77
78 --------------------------------------------------------------------------------------------------------------------------------
79
80 #Get ArvadosFile or Subcollection size 
81
82 size <- arvadosFile$getSizeInBytes()
83 size <- arvadosSubcollection$getSizeInBytes()
84
85 --------------------------------------------------------------------------------------------------------------------------------
86
87 #Create new file in a collection
88
89 #Call structure
90
91 collection$add(arvadosFileOrSubcollectionOrFileName, optionalRelativePath)
92
93 #Example
94
95 collection$add("main.cpp", "cpp/src/")
96
97 #or
98
99 folder <- Subcollection$new("src")
100 file <- ArvadosFile$new("main.cpp")
101 folder$add(file)
102
103 collection$add(folder, "cpp")
104
105 #Both examples will add file "main.cpp" in "./cpp/src/" folder if folder exists.
106 #If subcollection contains more files or folders they will be added recursively.
107
108 #You can also add multiple files
109
110 collection$add(c("path/to/my/file.cpp", "path/to/other/file.cpp"))
111
112 --------------------------------------------------------------------------------------------------------------------------------
113
114 #Write to existing file (Override current content of the file)
115
116 arvadosFile <- collection$get("location/to/my/file.cpp")
117
118 arvadosFile$write("This is new file content")
119
120 --------------------------------------------------------------------------------------------------------------------------------
121
122 #Delete file from a collection
123
124 file <- collection$get("location/to/my/file.cpp")
125
126 file$removeFromCollection()
127
128 #Or
129
130 collection$remove(file)
131
132 #Both examples will remove file "file.cpp" from a collection
133 #If subcollection contains more files or folders they will be removed recursively.
134
135 #You can also remove multiple files
136
137 collection$remove(c("path/to/my/file.cpp", "path/to/other/file.cpp"))
138
139 --------------------------------------------------------------------------------------------------------------------------------
140
141 --------------------------------------------------------------------------------------------------------------------------------
142
143 #Get project:
144
145 arv$getProject("uuid")
146
147 --------------------------------------------------------------------------------------------------------------------------------
148
149 #List projects:
150
151 projects <- arv$listProjects(list("uuid", "=" "aaaaa-bbbbb-ccccccccccccccc"), limit = 10, offset = 2)
152
153 --------------------------------------------------------------------------------------------------------------------------------
154
155 #Delete project:
156
157 deletedProject <- arv$deleteProject("uuid")
158
159 --------------------------------------------------------------------------------------------------------------------------------
160
161 #Update project:
162
163 updatedProject <- arv$updateProject("uuid", list((name = "new_name", description = "new_desciption")))
164
165 --------------------------------------------------------------------------------------------------------------------------------
166
167 #Create project:
168
169 cratedProject <- arv$createProject(list(list(name = "project_name", description = "project_desciption")))
170
171 --------------------------------------------------------------------------------------------------------------------------------