diff options
| author | Joel Martin <github@martintribe.org> | 2014-11-03 21:19:13 -0600 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2015-01-09 16:16:44 -0600 |
| commit | 36737ae57ee106be16426bf9ef088380421ca0ec (patch) | |
| tree | d3c405f95ccf63ab3897a4f17566bcc149cd7bf3 /r/printer.r | |
| parent | 8128c69a1da03d3b8d62defb4533c3e3ae706682 (diff) | |
| download | mal-36737ae57ee106be16426bf9ef088380421ca0ec.tar.gz mal-36737ae57ee106be16426bf9ef088380421ca0ec.zip | |
R: add hash-map and metadata support.
Diffstat (limited to 'r/printer.r')
| -rw-r--r-- | r/printer.r | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/r/printer.r b/r/printer.r index 8cf90db..1957210 100644 --- a/r/printer.r +++ b/r/printer.r @@ -2,8 +2,8 @@ if(!exists("..types..")) source("types.r") -.pr_list <- function(..., print_readably=TRUE, join="") { - concatl(lapply(list(...), +.pr_list <- function(lst, print_readably=TRUE, join="") { + concatl(lapply(lst, function(e) .pr_str(e, print_readably)), sep=join) } @@ -11,14 +11,20 @@ if(!exists("..types..")) source("types.r") pr <- print_readably switch(class(exp), "List"={ - data <- paste(lapply(exp, function(e) .pr_str(e, pr)), - sep="", collapse=" ") - paste("(", data, ")", sep="", collapse="") + paste("(", .pr_list(exp, pr, " "), ")", sep="", collapse="") }, "Vector"={ - data <- paste(lapply(exp, function(e) .pr_str(e, pr)), - sep=" ", collapse=" ") - paste("[", data, "]", sep="", collapse="") + paste("[", .pr_list(exp, pr, " "), "]", sep="", collapse="") + }, + "HashMap"={ + hlst <- list() + if (length(exp) > 0) { + for(k in ls(exp)) { + hlst[[length(hlst)+1]] <- k + hlst[[length(hlst)+1]] <- exp[[k]] + } + } + paste("{", .pr_list(hlst, pr, " "), "}", sep="", collapse="") }, "character"={ if (print_readably) { |
