Skip to content

Commit

Permalink
add alias, tests
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Sep 12, 2023
1 parent 3c11b38 commit 33e0819
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ S3method(normalize,matrix)
S3method(normalize,numeric)
S3method(plot,visualisation_recipe)
S3method(print,data_codebook)
S3method(print,data_seek)
S3method(print,dw_data_peek)
S3method(print,dw_data_tabulate)
S3method(print,dw_data_tabulates)
Expand Down Expand Up @@ -236,6 +237,7 @@ export(data_rename_rows)
export(data_reorder)
export(data_restoretype)
export(data_rotate)
export(data_seek)
export(data_select)
export(data_separate)
export(data_tabulate)
Expand Down
21 changes: 19 additions & 2 deletions R/seek_variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ seek_variables <- function(data, pattern, seek = c("names", "labels"), fuzzy = F
}
}
}
# get unique variable indices
c(pos1, pos2, pos3)
}))

Expand All @@ -143,10 +142,28 @@ seek_variables <- function(data, pattern, seek = c("names", "labels"), fuzzy = F
character(1)
)

data.frame(
out <- data.frame(
index = pos,
column = colnames(data)[pos],
labels = labels,
stringsAsFactors = FALSE
)
# no row names
rownames(out) <- NULL

class(out) <- c("data_seek", "data.frame")
out
}

# alias
#' @rdname seek_variables
#' @export
data_seek <- seek_variables


# methods ---------------------------------------------------------------------

#' @export
print.data_seek <- function(x, ...) {
cat(insight::export_table(x, ...))
}
3 changes: 3 additions & 0 deletions man/seek_variables.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions tests/testthat/_snaps/data_seek.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# seek_variables - print

Code
seek_variables(iris, "Length")
Output
index | column | labels
-----------------------------------
1 | Sepal.Length | Sepal.Length
3 | Petal.Length | Petal.Length

Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,7 @@ test_that("seek_variables - valid input", {
expect_error(seek_variables(rnorm(10), "Length"), regex = "`data` must be a data frame.")
expect_error(seek_variables(iris, "Length", seek = "somewhere"), regex = "`seek` must be")
})

test_that("seek_variables - print", {
expect_snapshot(seek_variables(iris, "Length"))
})

0 comments on commit 33e0819

Please sign in to comment.