Fixed ArvadosFile/Subcollection move bug and improved http query
[arvados.git] / sdk / R / R / util.R
index 8d4bcc0097fe0e4dcc626c2ad45b989e5ec48dcb..f6a582ff177b3b9aea4234486868142e19f10c59 100644 (file)
@@ -13,3 +13,41 @@ trimFromEnd <- function(sample, trimCharacters)
 
     sample
 }
+
+RListToPythonList <- function(sample, separator = ", ")
+{
+    pythonArrayContent <- sapply(sample, function(sampleUnit)
+    {
+        if((is.vector(sampleUnit) || is.list(sampleUnit)) &&
+            length(sampleUnit) > 1)
+        {
+            return(RListToPythonList(sampleUnit, separator))
+        }
+        else
+        {
+            return(paste0("\"", sampleUnit, "\""))
+        }
+    })
+
+    return(paste0("[", paste0(pythonArrayContent, collapse = separator), "]"))
+}
+
+appendToStartIfNotExist <- function(sample, characters)
+{
+    if(!startsWith(sample, characters))
+        sample <- paste0(characters, sample)
+
+    sample
+}
+
+splitToPathAndName = function(path)
+{
+    path <- appendToStartIfNotExist(path, "/")
+    components <- unlist(stringr::str_split(path, "/"))
+    nameAndPath <- list()
+    nameAndPath$name <- components[length(components)]
+    nameAndPath$path <- trimFromStart(paste0(components[-length(components)], collapse = "/"),
+                                      "/")
+    
+    nameAndPath
+}