| #' @examples | #' @examples | ||||
| #' dput_parser("x") | #' dput_parser("x") | ||||
| #' dput_parser(c("x", "y")) | #' dput_parser(c("x", "y")) | ||||
| dput_parser <- function(x) { | |||||
| ifelse(length(x) == 1, | |||||
| sprintf("'%s'", x), | |||||
| paste0("c(", | |||||
| paste(sprintf("'%s'", x), collapse = ", "), | |||||
| ")")) | |||||
| dput_parser <- function(x) UseMethod("dput_parser") | |||||
| dput_parser.character <- function(x) { | |||||
| if (length(x) == 1) { | |||||
| sprintf('"%s"', x) | |||||
| } else { | |||||
| x <- capture.output(dput(x)) | |||||
| paste(x, collapse = "") | |||||
| } | |||||
| } | } | ||||
| #' Adds color to processed tidy data | #' Adds color to processed tidy data |
| expect_equivalent(get_quos_names(x:y), "x:y") | expect_equivalent(get_quos_names(x:y), "x:y") | ||||
| expect_equivalent(get_quos_names(-x, -y, -z), c("-x", "-y", "-z")) | expect_equivalent(get_quos_names(-x, -y, -z), c("-x", "-y", "-z")) | ||||
| }) | }) | ||||
| test_that("dput_parsers works", { | |||||
| expect_equal(dput_parser("x"), '"x"') | |||||
| expect_equal(dput_parser(c("x", "y")), 'c("x", "y")') | |||||
| }) |