Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. write_pgfkeys <- function(x, ...) {
  2. UseMethod("write_pgfkeys")
  3. }
  4.  
  5. .pgfkey <- function(key, value) {
  6. str_c("\\pgfkeysetvalue{", key, "}{", value, "}")
  7. }
  8.  
  9. write_pgfkeys.default <- function(x, path=NULL, root = "/data/", ...) {
  10. keys <- str_c(root, names(x)) %>%
  11. # ensure leading and trailing / and no //
  12. str_replace("^/*", "/") %>%
  13. str_replace("/*$", "/") %>%
  14. str_replace("//", "/")
  15.  
  16. out <- str_c(map2_chr(keys, as.character(x), .pgfkey), collapse = "\n")
  17. if (!is.null(path)) {
  18. cat(out, file = path)
  19. }
  20. invisible(out)
  21. }
  22.  
  23. write_pgfkeys.environment <- function(x, ....) {
  24. v <- set_names(map_chr(names(x), function(i) as.character(x[[i]])),
  25. names(x))
  26. write_pgfkeys.character(v)
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement