Skip to content
Snippets Groups Projects
Commit f17a8da3 authored by Mathieu Loiseau's avatar Mathieu Loiseau
Browse files

Now works with just one field

parent 976c4080
No related branches found
No related tags found
No related merge requests found
......@@ -345,8 +345,14 @@ Batchator <- R6Class("Batchator",
loadContent = function(file_path){
tryCatch({
csvM <- read.csv(file=file_path, header = FALSE)
self$field_list <- as.vector(t(csvM[1,]))
self$content <- csvM[-1,]
if(ncol(csvM) == 1){
self$field_list <- as.vector(csvM[1,])
self$content <- as.vector(csvM[-1,])
}
else{
self$field_list <- as.vector(t(csvM[1,]))
self$content <- csvM[-1,]
}
},
error = function(e){
print(paste(e$message, "No content loaded"))
......@@ -365,21 +371,33 @@ Batchator <- R6Class("Batchator",
warning("Either no content or no templates, use loadContent, setPageNamePattern and/or loadTemplate.")
}
else{
for(i in 1:nrow(self$content)){
self$wiki$resetContent(str_replace_all(self$template,
setNames(as.vector(t(self$content[i,])),
self$field_list)))
self$wiki$setPage(str_replace_all(self$page_name_pattern,
setNames(as.vector(t(self$content[i,])),
self$field_list)))
self$wiki$postContent()
if(!is.null(nrow(self$content))){
for(i in 1:nrow(self$content)){
self$wiki$resetContent(str_replace_all(self$template,
setNames(as.vector(t(self$content[i,])),
self$field_list)))
self$wiki$setPage(str_replace_all(self$page_name_pattern,
setNames(as.vector(t(self$content[i,])),
self$field_list)))
self$wiki$postContent()
}
}
else{
for(i in 1:length(self$content)){
self$wiki$resetContent(str_replace_all(self$template,
setNames(as.vector(t(self$content[i])),
self$field_list)))
self$wiki$setPage(str_replace_all(self$page_name_pattern,
setNames(as.vector(t(self$content[i])),
self$field_list)))
self$wiki$postContent()
}
}
}
},
error = function(e){
print(e$message)
})
}
)
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment