Преглед изворни кода

Refactor dput_parser() and add tests

pull/18/merge
Garrick Aden-Buie пре 7 година
родитељ
комит
c6d670cca3
2 измењених фајлова са 14 додато и 6 уклоњено
  1. +9
    -6
      R/tidyr_helpers.R
  2. +5
    -0
      tests/testthat/test-tidyr_helpers.R

+ 9
- 6
R/tidyr_helpers.R Прегледај датотеку

@@ -25,12 +25,15 @@ get_quos_names <- function(...) {
#' @examples
#' dput_parser("x")
#' 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

+ 5
- 0
tests/testthat/test-tidyr_helpers.R Прегледај датотеку

@@ -5,3 +5,8 @@ test_that("get_quos_names works", {
expect_equivalent(get_quos_names(x:y), "x:y")
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")')
})

Loading…
Откажи
Сачувај