diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml
deleted file mode 100644
index ed7650c..0000000
--- a/.github/workflows/pkgdown.yaml
+++ /dev/null
@@ -1,48 +0,0 @@
-# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
-# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
-on:
- push:
- branches: [main, master]
- pull_request:
- branches: [main, master]
- release:
- types: [published]
- workflow_dispatch:
-
-name: pkgdown
-
-jobs:
- pkgdown:
- runs-on: ubuntu-latest
- # Only restrict concurrency for non-PR jobs
- concurrency:
- group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
- env:
- GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
- permissions:
- contents: write
- steps:
- - uses: actions/checkout@v3
-
- - uses: r-lib/actions/setup-pandoc@v2
-
- - uses: r-lib/actions/setup-r@v2
- with:
- use-public-rspm: true
-
- - uses: r-lib/actions/setup-r-dependencies@v2
- with:
- extra-packages: any::pkgdown, local::.
- needs: website
-
- - name: Build site
- run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
- shell: Rscript {0}
-
- - name: Deploy to GitHub pages 🚀
- if: github.event_name != 'pull_request'
- uses: JamesIves/github-pages-deploy-action@v4.4.1
- with:
- clean: false
- branch: gh-pages
- folder: docs
diff --git a/.github/workflows/test-rotemplate.yaml b/.github/workflows/test-rotemplate.yaml
new file mode 100644
index 0000000..cb7ae95
--- /dev/null
+++ b/.github/workflows/test-rotemplate.yaml
@@ -0,0 +1,11 @@
+on:
+ push:
+ pull_request:
+
+name: Test-docs
+
+jobs:
+ Test-docs:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: ropensci-org/rotemplate@main
diff --git a/DESCRIPTION b/DESCRIPTION
index c929295..01bdb66 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -2,26 +2,60 @@ Package: visdat
Title: Preliminary Visualisation of Data
Version: 0.6.0.9000
Authors@R: c(
- person("Nicholas", "Tierney", role = c("aut", "cre"),
- email = "nicholas.tierney@gmail.com",
- comment = c(ORCID = "https://orcid.org/0000-0003-1460-8722")),
- person("Sean", "Hughes", role = "rev",
- comment =c(ORCID = "https://orcid.org/0000-0002-9409-9405",
- "Sean Hughes reviewed the package for rOpenSci,
- see https://github.com/ropensci/onboarding/issues/87")),
- person("Mara", "Averick", role = "rev",
- comment = "Mara Averick reviewed the package for rOpenSci, see
- https://github.com/ropensci/onboarding/issues/87"),
- person("Stuart", "Lee", role = c("ctb")),
- person("Earo", "Wang", role = c("ctb")),
- person("Nic", "Crane", role = c("ctb")),
- person("Christophe", "Regouby", role=c("ctb")),
- person("Jordi", "Rosell", role=c("ctb"))
- )
+ person(
+ given = "Nicholas",
+ family = "Tierney",
+ role = c("aut", "cre"),
+ email = "nicholas.tierney@gmail.com",
+ comment = c(ORCID = "0000-0003-1460-8722")
+ ),
+ person(
+ given = "Sean",
+ family = "Hughes",
+ role = "rev",
+ comment = c(
+ ORCID = "0000-0002-9409-9405",
+ "Sean Hughes reviewed the package for rOpenSci, see
+ https://github.com/ropensci/onboarding/issues/87"
+ )
+ ),
+ person(
+ given = "Mara",
+ family = "Averick",
+ role = "rev",
+ comment = "Mara Averick reviewed the package for rOpenSci, see
+ https://github.com/ropensci/onboarding/issues/87"
+ ),
+ person(
+ given = "Stuart",
+ family = "Lee",
+ role = c("ctb")
+ ),
+ person(
+ given = "Earo",
+ family = "Wang",
+ role = c("ctb")
+ ),
+ person(
+ given = "Nic",
+ family ="Crane",
+ role = c("ctb")
+ ),
+ person(
+ given = "Christophe",
+ family = "Regouby",
+ role=c("ctb")
+ ),
+ person(
+ given = "Jordi",
+ family ="Rosell",
+ role=c("ctb")
+ )
+ )
Description: Create preliminary exploratory data visualisations of an entire
dataset to identify problems or unexpected features using 'ggplot2'.
Depends:
- R (>= 3.2.2)
+ R (>= 4.2.0)
License: MIT + file LICENSE
LazyData: true
Imports:
@@ -30,13 +64,13 @@ Imports:
dplyr,
purrr,
readr,
- magrittr,
stats,
tibble,
glue,
forcats,
cli,
- scales
+ scales,
+ rlang
URL: https://docs.ropensci.org/visdat/, https://github.com/ropensci/visdat
BugReports: https://github.com/ropensci/visdat/issues
Suggests:
@@ -51,6 +85,6 @@ Suggests:
VignetteBuilder: knitr
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
-Language: en-US
+Language: en-GB
Config/testthat/edition: 3
Config/roxygen2/version: 8.0.0
diff --git a/NAMESPACE b/NAMESPACE
index e05a5aa..5012d8d 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -9,7 +9,6 @@ S3method(data_vis_dat,grouped_df)
S3method(data_vis_miss,data.frame)
S3method(data_vis_miss,default)
S3method(data_vis_miss,grouped_df)
-export("%>%")
export(abbreviate_vars)
export(data_vis_cor)
export(data_vis_dat)
@@ -23,6 +22,5 @@ export(vis_guess)
export(vis_histogram)
export(vis_miss)
export(vis_value)
-importFrom(magrittr,"%>%")
importFrom(stats,cor)
importFrom(stats,setNames)
diff --git a/NEWS.md b/NEWS.md
index d09a903..c09df0c 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -8,6 +8,11 @@
* Resolved issue where text on axis was floating up higher - #171 (PR #174).
+## Misc
+
+* Remove magrittr; Use `|>` internally over `%>%`
+* Depend on R 4.2.0
+
# visdat 0.6.0 (2023/02/01) "Superman, Lazlo Bane"
## New Feature
@@ -27,7 +32,7 @@
* resolve bug where `vis_value()` displayed constant values as NA values (#128) - these constant values are now shown as 1.
* removed use of the now deprecated "aes_string" from ggplot2
* output of plot in `vis_expect` would reorder columns ([#133](https://github.com/ropensci/visdat/issues/133)), fixed in [#143](https://github.com/ropensci/visdat/pull/134) by [@muschellij2](https://github.com/muschellij2).
-* `vis_miss()` displayed missing percentages between 0.1% and 0.5% as 0% due to rounding. Now it dislpays "<1%" by @zeehio at https://github.com/ropensci/visdat/pull/162.
+* `vis_miss()` displayed missing percentages between 0.1% and 0.5% as 0% due to rounding. Now it displays "<1%" by @zeehio at https://github.com/ropensci/visdat/pull/162.
## Misc
@@ -52,8 +57,8 @@
## Bug Fix
-* [Jim Hester](https://github.com/jimhester) fixed recent changes in readr 1.2.0 in PR [#103](https://github.com/ropensci/visdat/pull/103), which changes the default behavior of the `guess_parser`, to not
-guess integer types by default. To opt-into the current behavior you
+* [Jim Hester](https://github.com/jimhester) fixed recent changes in readr 1.2.0 in PR [#103](https://github.com/ropensci/visdat/pull/103), which changes the default behaviour of the `guess_parser`, to not
+guess integer types by default. To opt-into the current behaviour you
need to pass `guess_integer = TRUE.`
# visdat 0.5.1 (2018/07/02) "The Northern Lights Moonwalker"
diff --git a/R/abbreviate.R b/R/abbreviate.R
index bc9c9fc..4b53660 100644
--- a/R/abbreviate.R
+++ b/R/abbreviate.R
@@ -18,14 +18,14 @@
#' )
#'
#' vis_miss(long_data)
-#' long_data %>% abbreviate_vars() %>% vis_miss()
+#' long_data |> abbreviate_vars() |> vis_miss()
#' @export
abbreviate_vars <- function(data, min_length = 10) {
test_if_dataframe(data)
dplyr::rename_with(
data,
- .fn = ~ abbreviate(.x, minlength = min_length, method = "both"),
+ .fn = \(x) abbreviate(x, minlength = min_length, method = "both"),
# this didn't work with ncar_over for some reason?
.cols = dplyr::everything()
)
diff --git a/R/data-typical-data-large.R b/R/data-typical-data-large.R
index af1c0b7..f292972 100644
--- a/R/data-typical-data-large.R
+++ b/R/data-typical-data-large.R
@@ -24,7 +24,7 @@
#' \item{Employment}{employee status}
#' \item{Eye}{eye colour}
#' \item{Grade}{percent grades}
-#' \item{Grade_Level}{favorite school grade}
+#' \item{Grade_Level}{favourite school grade}
#' \item{Group}{control or treatment}
#' \item{hair}{hair colours - "brown", "black", "blonde", or "red"}
#' \item{Height}{height in cm}
@@ -35,12 +35,13 @@
#' \item{Level}{levels between 1 and 4}
#' \item{Likert}{likert response - "strongly agree", "agree", and so on}
#' \item{Lorem_Ipsum}{lorem ipsum text}
-#' \item{Marital}{marital status- "married", "divorced", "widowed", "separated", etc}
+#' \item{Marital}{marital status- "married", "divorced", "widowed",
+#' "separated", etc}
#' \item{Military}{miliary branch they are in}
-#' \item{Month}{their favorite month}
+#' \item{Month}{their favourite month}
#' \item{Name}{their name}
#' \item{Normal}{a random normal number}
-#' \item{Political}{their favorite political party}
+#' \item{Political}{their favourite political party}
#' \item{Race}{their race}
#' \item{Religion}{their religion}
#' \item{SAT}{their SAT score}
diff --git a/R/data-vis-cor.R b/R/data-vis-cor.R
index be88b09..c877297 100644
--- a/R/data-vis-cor.R
+++ b/R/data-vis-cor.R
@@ -13,8 +13,8 @@
#' \dontrun{
#' #return vis_dat data for each group
#' library(dplyr)
-#' airquality %>%
-#' group_by(Month) %>%
+#' airquality |>
+#' group_by(Month) |>
#' data_vis_cor()
#' }
data_vis_cor <- function(x, ...) {
@@ -52,14 +52,14 @@ data_vis_cor.data.frame <- function(
na_action = "pairwise.complete.obs",
...
) {
- stats::cor(x, method = cor_method, use = na_action) %>%
- as.data.frame() %>%
- tibble::rownames_to_column() %>%
+ stats::cor(x, method = cor_method, use = na_action) |>
+ as.data.frame() |>
+ tibble::rownames_to_column() |>
tidyr::pivot_longer(
cols = -rowname,
names_to = "key",
values_to = "value"
- ) %>%
+ ) |>
purrr::set_names(c("row_1", "row_2", "value"))
}
diff --git a/R/data-vis-dat.R b/R/data-vis-dat.R
index c1b6590..c3e8622 100644
--- a/R/data-vis-dat.R
+++ b/R/data-vis-dat.R
@@ -13,8 +13,8 @@
#' \dontrun{
#' #return vis_dat data for each group
#' library(dplyr)
-#' airquality %>%
-#' group_by(Month) %>%
+#' airquality |>
+#' group_by(Month) |>
#' data_vis_dat()
#' }
data_vis_dat <- function(x, ...) {
@@ -30,9 +30,9 @@ data_vis_dat.default <- function(x, ...) {
#' @rdname data-vis-dat
#' @export
data_vis_dat.data.frame <- function(x, ...) {
- x %>%
- fingerprint_df() %>%
- vis_gather_() %>%
+ x |>
+ fingerprint_df() |>
+ vis_gather_() |>
# get the values here so plotly can make them visible
dplyr::mutate(value = vis_extract_value_(x))
}
diff --git a/R/data-vis-miss.R b/R/data-vis-miss.R
index 4982bdb..f52a768 100644
--- a/R/data-vis-miss.R
+++ b/R/data-vis-miss.R
@@ -13,8 +13,8 @@
#' \dontrun{
#' #return vis_dat data for each group
#' library(dplyr)
-#' airquality %>%
-#' group_by(Month) %>%
+#' airquality |>
+#' group_by(Month) |>
#' data_vis_miss()
#' }
data_vis_miss <- function(x, ...) {
@@ -40,16 +40,15 @@ data_vis_miss.default <- function(x, ...) {
#' @rdname data-vis-miss
#' @export
data_vis_miss.data.frame <- function(x, cluster = FALSE, ...) {
- x.na <- x %>%
- purrr::map_df(~ fingerprint(.x) %>% is.na)
+ x.na <- x |>
+ purrr::map_df(\(x) fingerprint(x) |> is.na())
# switch for creating the missing clustering
if (cluster) {
# this retrieves a row order of the clustered missingness
- row_order_index <-
- stats::dist(x.na * 1) %>%
- stats::hclust(method = "mcquitty") %>%
- stats::as.dendrogram() %>%
+ row_order_index <- stats::dist(x.na * 1) |>
+ stats::hclust(method = "mcquitty") |>
+ stats::as.dendrogram() |>
stats::order.dendrogram()
} else {
row_order_index <- seq_len(nrow(x))
@@ -63,8 +62,8 @@ data_vis_miss.data.frame <- function(x, cluster = FALSE, ...) {
# then the contents of that variable (value)
vis_miss_data <- as.data.frame(x.na[row_order_index, ])
- vis_miss_data %>%
- vis_gather_() %>%
+ vis_miss_data |>
+ vis_gather_() |>
# add info for plotly mousover
dplyr::mutate(value = vis_extract_value_(vis_miss_data))
}
diff --git a/R/internals.R b/R/internals.R
index 6a673af..d025b9b 100644
--- a/R/internals.R
+++ b/R/internals.R
@@ -12,7 +12,8 @@
#'
fingerprint <- function(x) {
# is the data missing?
- if (!is.list(x)) {
+ data_missing <- !is.list(x)
+ if (data_missing) {
ifelse(
is.na(x),
# yes? Leave as is NA
@@ -22,7 +23,7 @@ fingerprint <- function(x) {
)
} else {
ifelse(
- purrr::map_lgl(x, ~ length(.x) == 0),
+ purrr::map_lgl(x, \(x) length(x) == 0),
# yes? Leave as is NA
yes = NA,
# no? make that value no equal to the class of this cell.
@@ -53,14 +54,14 @@ fingerprint_df <- function(x) {
#' @noRd
#'
vis_gather_ <- function(x) {
- x %>%
- dplyr::mutate(rows = dplyr::row_number()) %>%
+ x |>
+ dplyr::mutate(rows = dplyr::row_number()) |>
tidyr::pivot_longer(
cols = -rows,
names_to = "variable",
values_to = "valueType",
values_transform = list(valueType = as.character)
- ) %>%
+ ) |>
dplyr::arrange(rows, variable, valueType)
}
@@ -118,6 +119,29 @@ vis_create_ <- function(x) {
ggplot2::guides(colour = "none")
}
+vis_dat_scale_fill_manual <- function(values) {
+ ggplot2::scale_fill_manual(
+ limits = c(
+ "character",
+ "date",
+ "factor",
+ "integer",
+ "logical",
+ "numeric"
+ ),
+ breaks = c(
+ "character", # red
+ "date", # orange
+ "factor", # yellow
+ "integer", # light blue
+ "logical", # mid blue
+ "numeric"
+ ), # dark blue
+ values = values,
+ na.value = "grey"
+ )
+}
+
#' (Internal) Add a specific palette to a visdat plot
#'
#' @param vis_plot visdat plot created using `vis_gather_`, `vis_extract_value`
@@ -162,50 +186,9 @@ add_vis_dat_pal <- function(vis_plot, palette) {
if (palette == "default") {
vis_plot
} else if (palette == "qual") {
- vis_plot +
- ggplot2::scale_fill_manual(
- limits = c(
- "character",
- "date",
- "factor",
- "integer",
- "logical",
- "numeric"
- ),
- breaks = c(
- "character", # red
- "date", # orange
- "factor", # yellow
- "integer", # light blue
- "logical", # mid blue
- "numeric"
- ), # dark blue
- values = vis_pal_qual,
- na.value = "grey",
- drop = FALSE
- )
+ vis_plot + vis_dat_scale_fill_manual(vis_pal_qual)
} else if (palette == "cb_safe") {
- vis_plot +
- ggplot2::scale_fill_manual(
- limits = c(
- "character",
- "date",
- "factor",
- "integer",
- "logical",
- "numeric"
- ),
- breaks = c(
- "character", # red
- "date", # orange
- "factor", # yellow
- "integer", # light blue
- "logical", # mid blue
- "numeric"
- ), # dark blue
- values = vis_pal_cb_safe,
- na.value = "grey"
- )
+ vis_plot + vis_dat_scale_fill_manual(vis_pal_cb_safe)
} else {
cli::cli_abort(
c(
@@ -228,13 +211,13 @@ add_vis_dat_pal <- function(vis_plot, palette) {
label_col_missing_pct <- function(x, col_order_index) {
# present everything in the right order
- labelled_pcts <- colMeans(is.na(x))[col_order_index] %>%
+ labelled_pcts <- colMeans(is.na(x))[col_order_index] |>
purrr::map_chr(function(x) {
dplyr::case_when(
x == 0 ~ "0%",
x < 0.001 ~ "<0.1%",
x < 0.01 ~ "<1%",
- x >= 0.01 ~ scales::percent(x, accuracy = 1),
+ x >= 0.01 ~ scales::percent(x, accuracy = 1)
)
})
@@ -379,8 +362,8 @@ scale_01 <- function(x) {
}
group_by_fun <- function(data, .fun, ...) {
- tidyr::nest(data) %>%
- dplyr::mutate(data = purrr::map(data, .fun, ...)) %>%
+ tidyr::nest(data) |>
+ dplyr::mutate(data = purrr::map(data, .fun, ...)) |>
tidyr::unnest(cols = c(data))
}
@@ -434,3 +417,23 @@ n_miss_col <- function(data, sort = FALSE) {
n_missing_cols
}
+
+test_if_dims_identical <- function(
+ x,
+ y,
+ arg_x = rlang::caller_arg(x),
+ arg_y = rlang::caller_arg(y),
+ call = rlang::caller_env()
+) {
+ if (!identical(dim(x), dim(y))) {
+ cli::cli_abort(
+ message = c(
+ "{.fun vis_compare} requires identical dimensions of {.arg {arg_x}} \\
+ and {.arg {arg_y}}",
+ "The dimensions of {.arg {arg_x}} are: {dim(x)}",
+ "The dimensions of {.arg {arg_y}} are: {dim(y)}"
+ ),
+ call = call
+ )
+ }
+}
diff --git a/R/utils-pipe.R b/R/utils-pipe.R
deleted file mode 100644
index fd0b1d1..0000000
--- a/R/utils-pipe.R
+++ /dev/null
@@ -1,14 +0,0 @@
-#' Pipe operator
-#'
-#' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details.
-#'
-#' @name %>%
-#' @rdname pipe
-#' @keywords internal
-#' @export
-#' @importFrom magrittr %>%
-#' @usage lhs \%>\% rhs
-#' @param lhs A value or the magrittr placeholder.
-#' @param rhs A function call using the magrittr semantics.
-#' @return The result of calling `rhs(lhs)`.
-NULL
diff --git a/R/vis-binary.R b/R/vis-binary.R
index 9b97262..0acebc5 100644
--- a/R/vis-binary.R
+++ b/R/vis-binary.R
@@ -31,14 +31,14 @@ vis_binary <- function(
) {
test_if_all_binary(data)
- data %>%
- vis_gather_() %>%
- dplyr::mutate(value = vis_extract_value_(data)) %>%
+ data |>
+ vis_gather_() |>
+ dplyr::mutate(value = vis_extract_value_(data)) |>
dplyr::mutate(
valueType = forcats::as_factor(valueType),
value = forcats::as_factor(value),
variable = forcats::fct_relevel(variable, order)
- ) %>%
+ ) |>
vis_create_() +
# change the limits etc.
ggplot2::guides(fill = ggplot2::guide_legend(title = "Value")) +
diff --git a/R/vis-compare.R b/R/vis-compare.R
index ceb8ed7..f067af0 100644
--- a/R/vis-compare.R
+++ b/R/vis-compare.R
@@ -27,26 +27,16 @@ vis_compare <- function(df1, df2) {
test_if_dataframe(df1)
test_if_dataframe(df2)
-
- if (!identical(dim(df1), dim(df2))) {
- cli::cli_abort(
- c(
- "{.fun vis_compare} requires identical dimensions of {.arg df1} and \\
- {.arg df2}",
- "The dimensions of {.arg df1} are: {dim(df1)}",
- "The dimensions of {.arg df2} are: {dim(df2)}"
- )
- )
- }
+ test_if_dims_identical(df1, df2)
v_identical <- Vectorize(identical)
df_diff <- purrr::map2_df(df1, df2, v_identical)
- d <- df_diff %>%
- as.data.frame() %>%
- purrr::map_df(compare_print) %>%
- vis_gather_() %>%
+ d <- df_diff |>
+ as.data.frame() |>
+ purrr::map_df(compare_print) |>
+ vis_gather_() |>
dplyr::mutate(
value_df1 = vis_extract_value_(df1),
value_df2 = vis_extract_value_(df2)
@@ -62,8 +52,7 @@ vis_compare <- function(df1, df2) {
) +
# text assists with plotly mouseover
# text = c("value_df1", "value_df2"))) +
- # this test code has been removed as ggplot2 version 3.0.0
- # breaks.
+ # this test code has been removed as ggplot2 version 3.0.0 breaks.
# Logged in issue https://github.com/ropensci/visdat/issues/89
ggplot2::geom_raster(ggplot2::aes(fill = valueType)) +
@@ -77,13 +66,13 @@ vis_compare <- function(df1, df2) {
ggplot2::scale_fill_manual(
limits = c("same", "different"),
breaks = c(
- "same", # red
- "different"
- ), # dark blue
+ "same", # orange
+ "different" # dark blue
+ ),
values = c(
"#fc8d59", # Orange
- "#91bfdb"
- ), # blue
+ "#91bfdb" # blue
+ ),
na.value = "grey"
) +
# flip the axes
diff --git a/R/vis-cor.R b/R/vis-cor.R
index 584b9a1..1b8a47c 100644
--- a/R/vis-cor.R
+++ b/R/vis-cor.R
@@ -11,7 +11,7 @@
#' values present. This can be "everything", "all.obs", "complete.obs",
#' "na.or.complete", or "pairwise.complete.obs" (default). This option is
#' taken from the `cor` function argument `use`.,
-#' @param facet bare unqouted variable to use for facetting
+#' @param facet bare unquoted variable to use for facetting
#' @param ... extra arguments you may want to pass to `cor`
#'
#' @return ggplot2 object
diff --git a/R/vis-dat.R b/R/vis-dat.R
index bb25153..2b0d6e4 100644
--- a/R/vis-dat.R
+++ b/R/vis-dat.R
@@ -53,12 +53,12 @@
#' \dontrun{
#' library(nycflights13)
#' library(dplyr)
-#' flights %>%
-#' sample_n(1000) %>%
+#' flights |>
+#' sample_n(1000) |>
#' vis_dat()
#'
-#' flights %>%
-#' slice(1:1000) %>%
+#' flights |>
+#' slice(1:1000) |>
#' vis_dat()
#'}
#'
@@ -90,8 +90,8 @@ vis_dat <- function(
# reshape the dataframe ready for geom_raster
if (!missing(facet)) {
- vis_dat_data <- x %>%
- dplyr::group_by({{ facet }}) %>%
+ vis_dat_data <- x |>
+ dplyr::group_by({{ facet }}) |>
data_vis_dat()
col_order_index <- update_col_order_index(
diff --git a/R/vis-expect.R b/R/vis-expect.R
index dffa425..08d06dd 100644
--- a/R/vis-expect.R
+++ b/R/vis-expect.R
@@ -2,18 +2,18 @@
#'
#' `vis_expect` visualises certain conditions or values in your data. For
#' example, If you are not sure whether to expect -1 in your data, you could
-#' write: `vis_expect(data, ~.x == -1)`, and you can see if there are times
+#' write: `vis_expect(data, \(x) x == -1)`, and you can see if there are times
#' where the values in your data are equal to -1. You could also, for example,
#' explore a set of bad strings, or possible NA values and visualise where
-#' they are using \code{vis_expect(data, ~.x \%in\% bad_strings)} where
+#' they are using \code{vis_expect(data, \(x) x \%in\% bad_strings)} where
#' `bad_strings` is a character vector containing bad strings like `N A`
#' `N/A` etc.
#'
#' @param data a data.frame
-#' @param expectation a formula following the syntax: `~.x {condition}`.
-#' For example, writing `~.x < 20` would mean "where a variable value is less
-#' than 20, replace with NA", and \code{~.x \%in\% {vector}} would mean "where a
-#' variable has values that are in that vector".
+#' @param expectation a function, e.g., `\(x) {condition}`. For example, writing
+#' `\(x) x < 20` would mean "where a variable value is less than 20, replace
+#' with NA", and \code{\(x) \%in\% {vector}} would mean "where a variable has
+#' values that are in that vector".
#' @param show_perc logical. TRUE now adds in the \% of expectations are
#' TRUE or FALSE in the whole dataset into the legend. Default value is TRUE.
#' @return a ggplot2 object
@@ -32,9 +32,9 @@
#' NA, NA
#' )
#'
-#' vis_expect(dat_test, ~.x == -1)
+#' vis_expect(dat_test, \(x) x == -1)
#'
-#' vis_expect(airquality, ~.x == 5.1)
+#' vis_expect(airquality, \(x) x == 5.1)
#'
#' # explore some common NA strings
#'
@@ -54,7 +54,7 @@
#' "N A", "E", -101,
#' "na", "F", -1)
#'
-#' vis_expect(dat_ms, ~.x %in% common_nas)
+#' vis_expect(dat_ms, \(x) x %in% common_nas)
#'
#'
vis_expect <- function(data, expectation, show_perc = TRUE) {
@@ -66,32 +66,28 @@ vis_expect <- function(data, expectation, show_perc = TRUE) {
if (show_perc) {
temp <- expect_guide_label(data_expect)
-
p_expect_true_lab <- temp$p_expect_false_lab
-
p_expect_false_lab <- temp$p_expect_true_lab
# else if show_perc FALSE (do nothing)
} else {
p_expect_true_lab <- "TRUE"
-
p_expect_false_lab <- "FALSE"
}
colnames_data <- colnames(data_expect)
- data_expect <- data_expect %>%
- # expect_frame(expectation) %>%
- dplyr::mutate(rows = dplyr::row_number()) %>%
+ data_expect <- data_expect |>
+ tibble::rowid_to_column(var = "rows") |>
tidyr::pivot_longer(
cols = dplyr::all_of(colnames_data),
names_to = "variable",
values_to = "valueType",
values_transform = list(valueType = as.character)
)
- data_expect <- data_expect %>%
+ data_expect <- data_expect |>
dplyr::mutate(variable = factor(variable, levels = colnames_data))
- vis_expect_plot <- data_expect %>%
+ vis_expect_plot <- data_expect |>
ggplot2::ggplot(ggplot2::aes(x = variable, y = rows)) +
ggplot2::geom_raster(ggplot2::aes(fill = valueType)) +
ggplot2::theme_minimal() +
@@ -107,8 +103,7 @@ vis_expect <- function(data, expectation, show_perc = TRUE) {
"grey"
),
labels = c(p_expect_false_lab, p_expect_true_lab),
- # light gray
- na.value = "#E5E5E5"
+ na.value = "#E5E5E5" # light gray
) +
# change the limits etc.
ggplot2::guides(
@@ -142,8 +137,7 @@ vis_expect <- function(data, expectation, show_perc = TRUE) {
#' 1, "C"
#' )
#'
-#' expect_frame(dat_test,
-#' ~ .x == -1)
+#' expect_frame(dat_test, \(x) == -1)
#' }
expect_frame <- function(data, expectation) {
my_fun <- purrr::as_mapper(expectation)
diff --git a/R/vis-guess.R b/R/vis-guess.R
index 4c1bd6c..6a82ae5 100644
--- a/R/vis-guess.R
+++ b/R/vis-guess.R
@@ -48,8 +48,8 @@ vis_guess <- function(x, palette = "default") {
# x = messy_df
# suppress warnings here as this is just a note about combining classes
- d <- suppressWarnings(vis_gather_(x)) %>%
- dplyr::mutate(valueType = guess_type(valueType)) %>%
+ d <- suppressWarnings(vis_gather_(x)) |>
+ dplyr::mutate(valueType = guess_type(valueType)) |>
# value for plotly mouseover
dplyr::mutate(value = vis_extract_value_(x))
@@ -97,7 +97,7 @@ guess_type <- function(x) {
# of about 3. This is faster, for the moment.
output <- character(length(x))
- nas <- (x %>% fingerprint() %>% is.na() | is.na(x))
+ nas <- (x |> fingerprint() |> is.na() | is.na(x))
output[!nas] <- vapply(
FUN = readr::guess_parser,
diff --git a/R/vis-histogram.R b/R/vis-histogram.R
index dc2b0d6..b91c882 100644
--- a/R/vis-histogram.R
+++ b/R/vis-histogram.R
@@ -24,10 +24,10 @@ vis_histogram <- function(x, ...) {
}
vis_histogram_create <- function(data, ...) {
- data %>%
- dplyr::mutate(rows = dplyr::row_number()) %>%
- tidyr::pivot_longer(cols = -rows) %>%
- dplyr::filter(!is.na(value)) %>%
+ data |>
+ dplyr::mutate(rows = dplyr::row_number()) |>
+ tidyr::pivot_longer(cols = -rows) |>
+ dplyr::filter(!is.na(value)) |>
ggplot2::ggplot(ggplot2::aes(value)) +
ggplot2::facet_wrap(~name, scales = "free") +
ggplot2::geom_histogram(...) +
diff --git a/R/vis-miss.R b/R/vis-miss.R
index e602e54..30ee0ea 100644
--- a/R/vis-miss.R
+++ b/R/vis-miss.R
@@ -64,12 +64,12 @@
#' # if you have a large dataset, you might want to try downsampling:
#' library(nycflights13)
#' library(dplyr)
-#' flights %>%
-#' sample_n(1000) %>%
+#' flights |>
+#' sample_n(1000) |>
#' vis_miss()
#'
-#' flights %>%
-#' slice(1:1000) %>%
+#' flights |>
+#' slice(1:1000) |>
#' vis_miss()
#' }
#'
@@ -94,8 +94,8 @@ vis_miss <- function(
}
if (!missing(facet)) {
- vis_miss_data <- x %>%
- dplyr::group_by({{ facet }}) %>%
+ vis_miss_data <- x |>
+ dplyr::group_by({{ facet }}) |>
data_vis_miss(cluster)
col_order_index <- update_col_order_index(
@@ -114,15 +114,12 @@ vis_miss <- function(
if (show_perc) {
temp <- miss_guide_label(x_fingerprinted)
-
p_miss_lab <- temp$p_miss_lab
-
p_pres_lab <- temp$p_pres_lab
# else if show_perc FALSE
} else {
p_miss_lab <- "Missing"
-
p_pres_lab <- "Present"
}
@@ -149,7 +146,7 @@ vis_miss <- function(
if (ncol(x) == 1) {
if (show_perc_col) {
return(
- vis_miss_plot <- vis_miss_plot +
+ vis_miss_plot +
ggplot2::scale_x_discrete(
position = "top",
labels = label_col_missing_pct(
@@ -160,7 +157,7 @@ vis_miss <- function(
)
} else if (!show_perc_col) {
return(
- vis_miss_plot <- vis_miss_plot +
+ vis_miss_plot +
ggplot2::scale_x_discrete(
position = "top",
labels = col_order_index
@@ -194,9 +191,4 @@ vis_miss <- function(
}
return(vis_miss_plot)
-
- # guides(fill = guide_legend(title = "Type"))
- # Thanks to
- # http://www.markhneedham.com/blog/2015/02/27/rggplot-controlling-x-axis-order/
- # For the tip on using scale_x_discrete
-} # end of function
+}
diff --git a/R/vis-value.R b/R/vis-value.R
index b0f9397..c2e6da0 100644
--- a/R/vis-value.R
+++ b/R/vis-value.R
@@ -23,20 +23,20 @@
#' vis_value(airquality, viridis_option = "E")
#' \dontrun{
#' library(dplyr)
-#' diamonds %>%
-#' select_if(is.numeric) %>%
+#' diamonds |>
+#' select_if(is.numeric) |>
#' vis_value()
#'}
vis_value <- function(data, na_colour = "grey90", viridis_option = "D") {
test_if_all_numeric(data)
- purrr::map_dfr(data, scale_01) %>%
- vis_gather_() %>%
+ purrr::map_dfr(data, scale_01) |>
+ vis_gather_() |>
dplyr::mutate(
value = vis_extract_value_(data),
value = as.numeric(value),
valueType = as.numeric(valueType)
- ) %>%
+ ) |>
vis_create_() +
# change the limits etc.
ggplot2::guides(fill = ggplot2::guide_legend(title = "Value")) +
diff --git a/R/visdat-package.r b/R/visdat-package.r
index 2940148..3db04c1 100644
--- a/R/visdat-package.r
+++ b/R/visdat-package.r
@@ -18,14 +18,13 @@
#' Learn more about visdat at \url{https://docs.ropensci.org/visdat/}
#' @name visdat
#' @docType package
-#' @importFrom magrittr %>%
#' @importFrom stats cor
#' @importFrom stats setNames
#' @keywords internal
"_PACKAGE"
if (getRversion() >= "2.15.1") {
- utils::globalVariables(c("."))
+ utils::globalVariables(".")
}
globalVariables(c(
"valueGuess",
diff --git a/README.Rmd b/README.Rmd
index b68574b..4b028d4 100644
--- a/README.Rmd
+++ b/README.Rmd
@@ -5,7 +5,8 @@ output: github_document
```{r setup, echo = FALSE}
-
+# jarl-ignore-file true_false_symbol: vectors are deliberately bad
+# Date: 2026-08-12
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
@@ -170,7 +171,9 @@ Let's make some changes to the `chickwts`, and compare this new dataset:
```{r vis-compare-iris}
set.seed(2019-04-03-1105)
chickwts_diff <- chickwts
-chickwts_diff[sample(1:nrow(chickwts), 30),sample(1:ncol(chickwts), 2)] <- NA
+rows_to_na <- sample(seq_len(nrow(chickwts)), 30)
+cols_to_na <- sample(seq_len(ncol(chickwts)), 2)
+chickwts_diff[rows_to_na, cols_to_na] <- NA
vis_compare(chickwts_diff, chickwts)
diff --git a/README.md b/README.md
index cfc9269..6b35b20 100644
--- a/README.md
+++ b/README.md
@@ -192,7 +192,9 @@ Let’s make some changes to the `chickwts`, and compare this new dataset:
``` r
set.seed(2019-04-03-1105)
chickwts_diff <- chickwts
-chickwts_diff[sample(1:nrow(chickwts), 30),sample(1:ncol(chickwts), 2)] <- NA
+rows_to_na <- sample(seq_len(nrow(chickwts)), 30)
+cols_to_na <- sample(seq_len(ncol(chickwts)), 2)
+chickwts_diff[rows_to_na, cols_to_na] <- NA
vis_compare(chickwts_diff, chickwts)
```
@@ -340,7 +342,7 @@ vis_guess(messy_df)
vis_dat(messy_df)
```
-
+
So here we see that there are many different kinds of data in your
dataframe. As an analyst this might be a depressing finding. We can see
diff --git a/data-raw/create-binary-data.R b/data-raw/create-binary-data.R
index a206700..1c786a3 100644
--- a/data-raw/create-binary-data.R
+++ b/data-raw/create-binary-data.R
@@ -8,7 +8,7 @@ dat_bin <- tibble(
x = sample(x = c(0L, 1L), size = 100, replace = TRUE),
y = sample(x = c(0L, 1L), size = 100, replace = TRUE),
z = sample(x = c(0L, 1L), size = 100, replace = TRUE)
-) %>%
+) |>
mutate_at(vars(x, y), assign_na, 10)
usethis::use_data(dat_bin, overwrite = TRUE)
diff --git a/data-raw/create-typical-data-large.R b/data-raw/create-typical-data-large.R
index e85bc8a..6e0d85e 100644
--- a/data-raw/create-typical-data-large.R
+++ b/data-raw/create-typical-data-large.R
@@ -3,7 +3,7 @@ library(wakefield)
set.seed(1214)
typical_data_large <- r_data_theme(n = 300, data_theme = "the_works")
-typical_data_large <- typical_data_large %>%
+typical_data_large <- typical_data_large |>
mutate(Income = as.factor(Income), Age = as.character(Age))
use_data(typical_data_large, overwrite = TRUE)
diff --git a/data-raw/create-typical-data.R b/data-raw/create-typical-data.R
index 38d5cc4..3a9ff6f 100644
--- a/data-raw/create-typical-data.R
+++ b/data-raw/create-typical-data.R
@@ -13,8 +13,8 @@ typical_data <- r_data_frame(
smokes,
income,
died
-) %>%
- wakefield::r_na(cols = c(2, 3, 6, 8), prob = 0.1) %>%
+) |>
+ wakefield::r_na(cols = c(2, 3, 6, 8), prob = 0.1) |>
mutate(Income = as.factor(Income), Age = as.character(Age))
use_data(typical_data, overwrite = TRUE)
diff --git a/inst/WORDLIST b/inst/WORDLIST
index 794f52d..042bc83 100644
--- a/inst/WORDLIST
+++ b/inst/WORDLIST
@@ -1,61 +1,37 @@
CMD
Codecov
-Customising
-DOI
Funcions
GATC
Gilholm
-Hadley
Hanigan
Hawaiin
-JOSS
Lazlo
LoFi
McBain
Moonwalker
-Noam
ORCID
-README
-Sievert
-Trish
-Visualisation
-Visualise
-Visualises
-WORDLIST
-Wickham
aes
airquality
-amongst
appveyor
arg
-behaviour
cb
+centimeters
cividis
colorbrewer
colormap
+colors
colorspace
-colour
colourblindness
-coloured
-colouring
-colours
-customising
+com
dat
-dev
doco
-downsampling
errored
-extensibility
+etc
facetted
facetting
-focussed
-focusses
gdtools
ggplot
github
-grey
-http
-https
ipsum
iq
kendall
@@ -66,12 +42,12 @@ magrittr
mcquitty
miliary
mtcars
-na
ncol
nrow
nucleobases
+obs
onboarding
-organisation
+org
pearson
perc
pkgdown
@@ -80,23 +56,14 @@ protoype
qual
rOpenSci
readr
-rescales
ropensci
scico
spearman
-standardised
steelblue
svg
-travelled
travis
-unqoted
+var
vdiffr
-viridis
-vis
-visualisation
-visualisations
-visualise
-visualises
-visualising
wakefield
wesanderson
+yous
diff --git a/man/abbreviate_vars.Rd b/man/abbreviate_vars.Rd
index d8b36ff..931399c 100644
--- a/man/abbreviate_vars.Rd
+++ b/man/abbreviate_vars.Rd
@@ -28,5 +28,5 @@ long_data <- data.frame(
)
vis_miss(long_data)
-long_data \%>\% abbreviate_vars() \%>\% vis_miss()
+long_data |> abbreviate_vars() |> vis_miss()
}
diff --git a/man/data-vis-cor.Rd b/man/data-vis-cor.Rd
index 988e122..28068f0 100644
--- a/man/data-vis-cor.Rd
+++ b/man/data-vis-cor.Rd
@@ -52,8 +52,8 @@ data_vis_cor(airquality)
\dontrun{
#return vis_dat data for each group
library(dplyr)
-airquality \%>\%
- group_by(Month) \%>\%
+airquality |>
+ group_by(Month) |>
data_vis_cor()
}
data_vis_cor(airquality)
diff --git a/man/data-vis-dat.Rd b/man/data-vis-dat.Rd
index 8b7c35f..8ed9b0c 100644
--- a/man/data-vis-dat.Rd
+++ b/man/data-vis-dat.Rd
@@ -33,8 +33,8 @@ data_vis_dat(airquality)
\dontrun{
#return vis_dat data for each group
library(dplyr)
-airquality \%>\%
- group_by(Month) \%>\%
+airquality |>
+ group_by(Month) |>
data_vis_dat()
}
}
diff --git a/man/data-vis-miss.Rd b/man/data-vis-miss.Rd
index 110d3b8..d2a8700 100644
--- a/man/data-vis-miss.Rd
+++ b/man/data-vis-miss.Rd
@@ -39,8 +39,8 @@ data_vis_miss(airquality)
\dontrun{
#return vis_dat data for each group
library(dplyr)
-airquality \%>\%
- group_by(Month) \%>\%
+airquality |>
+ group_by(Month) |>
data_vis_miss()
}
data_vis_miss(airquality)
diff --git a/man/figures/README-iris-error-fix-1.png b/man/figures/README-iris-error-fix-1.png
index fc9d9fa..b5e3f95 100644
Binary files a/man/figures/README-iris-error-fix-1.png and b/man/figures/README-iris-error-fix-1.png differ
diff --git a/man/figures/README-vis-bin-1.png b/man/figures/README-vis-bin-1.png
index 8d99b8d..1e7fa72 100644
Binary files a/man/figures/README-vis-bin-1.png and b/man/figures/README-vis-bin-1.png differ
diff --git a/man/figures/README-vis-compare-iris-1.png b/man/figures/README-vis-compare-iris-1.png
index e7c50f3..f602c46 100644
Binary files a/man/figures/README-vis-compare-iris-1.png and b/man/figures/README-vis-compare-iris-1.png differ
diff --git a/man/figures/README-vis-cor-1.png b/man/figures/README-vis-cor-1.png
index d300465..af498bf 100644
Binary files a/man/figures/README-vis-cor-1.png and b/man/figures/README-vis-cor-1.png differ
diff --git a/man/figures/README-vis-dat-aq-1.png b/man/figures/README-vis-dat-aq-1.png
index e615143..7e54ecb 100644
Binary files a/man/figures/README-vis-dat-aq-1.png and b/man/figures/README-vis-dat-aq-1.png differ
diff --git a/man/figures/README-vis-dat-month-1.png b/man/figures/README-vis-dat-month-1.png
index 902e3a2..cca3b61 100644
Binary files a/man/figures/README-vis-dat-month-1.png and b/man/figures/README-vis-dat-month-1.png differ
diff --git a/man/figures/README-vis-expect-1.png b/man/figures/README-vis-expect-1.png
index 49513dc..a31fa7b 100644
Binary files a/man/figures/README-vis-expect-1.png and b/man/figures/README-vis-expect-1.png differ
diff --git a/man/figures/README-vis-guess-messy-df-1.png b/man/figures/README-vis-guess-messy-df-1.png
index 6617345..5e2a2d7 100644
Binary files a/man/figures/README-vis-guess-messy-df-1.png and b/man/figures/README-vis-guess-messy-df-1.png differ
diff --git a/man/figures/README-vis-guess-messy-df-2.png b/man/figures/README-vis-guess-messy-df-2.png
index e11bfa1..e102201 100644
Binary files a/man/figures/README-vis-guess-messy-df-2.png and b/man/figures/README-vis-guess-messy-df-2.png differ
diff --git a/man/figures/README-vis-miss-aq-1.png b/man/figures/README-vis-miss-aq-1.png
index ab2733c..125f43d 100644
Binary files a/man/figures/README-vis-miss-aq-1.png and b/man/figures/README-vis-miss-aq-1.png differ
diff --git a/man/figures/README-vis-miss-aq-cluster-1.png b/man/figures/README-vis-miss-aq-cluster-1.png
index d06bb02..4e0540b 100644
Binary files a/man/figures/README-vis-miss-aq-cluster-1.png and b/man/figures/README-vis-miss-aq-cluster-1.png differ
diff --git a/man/figures/README-vis-miss-aq-sort-miss-1.png b/man/figures/README-vis-miss-aq-sort-miss-1.png
index ab2733c..125f43d 100644
Binary files a/man/figures/README-vis-miss-aq-sort-miss-1.png and b/man/figures/README-vis-miss-aq-sort-miss-1.png differ
diff --git a/man/figures/README-vis-miss-mtcars-1.png b/man/figures/README-vis-miss-mtcars-1.png
index b5ed917..2981118 100644
Binary files a/man/figures/README-vis-miss-mtcars-1.png and b/man/figures/README-vis-miss-mtcars-1.png differ
diff --git a/man/figures/README-vis-miss-test-1.png b/man/figures/README-vis-miss-test-1.png
index 864e145..3247e67 100644
Binary files a/man/figures/README-vis-miss-test-1.png and b/man/figures/README-vis-miss-test-1.png differ
diff --git a/man/figures/README-vis-value-1.png b/man/figures/README-vis-value-1.png
index be065bd..31156c9 100644
Binary files a/man/figures/README-vis-value-1.png and b/man/figures/README-vis-value-1.png differ
diff --git a/man/pipe.Rd b/man/pipe.Rd
deleted file mode 100644
index a648c29..0000000
--- a/man/pipe.Rd
+++ /dev/null
@@ -1,20 +0,0 @@
-% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/utils-pipe.R
-\name{\%>\%}
-\alias{\%>\%}
-\title{Pipe operator}
-\usage{
-lhs \%>\% rhs
-}
-\arguments{
-\item{lhs}{A value or the magrittr placeholder.}
-
-\item{rhs}{A function call using the magrittr semantics.}
-}
-\value{
-The result of calling \code{rhs(lhs)}.
-}
-\description{
-See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details.
-}
-\keyword{internal}
diff --git a/man/typical_data.Rd b/man/typical_data.Rd
index ec40841..a7e6d00 100644
--- a/man/typical_data.Rd
+++ b/man/typical_data.Rd
@@ -1,5 +1,5 @@
% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/data-typical-data.r
+% Please edit documentation in R/data-typical-data.R
\docType{data}
\name{typical_data}
\alias{typical_data}
diff --git a/man/typical_data_large.Rd b/man/typical_data_large.Rd
index 097064b..eeaffd5 100644
--- a/man/typical_data_large.Rd
+++ b/man/typical_data_large.Rd
@@ -25,7 +25,7 @@ A data frame with 300 rows and 49 variables:
\item{Employment}{employee status}
\item{Eye}{eye colour}
\item{Grade}{percent grades}
-\item{Grade_Level}{favorite school grade}
+\item{Grade_Level}{favourite school grade}
\item{Group}{control or treatment}
\item{hair}{hair colours - "brown", "black", "blonde", or "red"}
\item{Height}{height in cm}
@@ -36,12 +36,13 @@ A data frame with 300 rows and 49 variables:
\item{Level}{levels between 1 and 4}
\item{Likert}{likert response - "strongly agree", "agree", and so on}
\item{Lorem_Ipsum}{lorem ipsum text}
-\item{Marital}{marital status- "married", "divorced", "widowed", "separated", etc}
+\item{Marital}{marital status- "married", "divorced", "widowed",
+"separated", etc}
\item{Military}{miliary branch they are in}
-\item{Month}{their favorite month}
+\item{Month}{their favourite month}
\item{Name}{their name}
\item{Normal}{a random normal number}
-\item{Political}{their favorite political party}
+\item{Political}{their favourite political party}
\item{Race}{their race}
\item{Religion}{their religion}
\item{SAT}{their SAT score}
diff --git a/man/vis_cor.Rd b/man/vis_cor.Rd
index 6cd0927..d47fe8f 100644
--- a/man/vis_cor.Rd
+++ b/man/vis_cor.Rd
@@ -25,7 +25,7 @@ values present. This can be "everything", "all.obs", "complete.obs",
"na.or.complete", or "pairwise.complete.obs" (default). This option is
taken from the \code{cor} function argument \code{use}.,}
-\item{facet}{bare unqouted variable to use for facetting}
+\item{facet}{bare unquoted variable to use for facetting}
\item{...}{extra arguments you may want to pass to \code{cor}}
}
diff --git a/man/vis_dat.Rd b/man/vis_dat.Rd
index 0246057..75c4d6f 100644
--- a/man/vis_dat.Rd
+++ b/man/vis_dat.Rd
@@ -67,12 +67,12 @@ vis_dat(airquality, palette = "qual")
\dontrun{
library(nycflights13)
library(dplyr)
-flights \%>\%
- sample_n(1000) \%>\%
+flights |>
+ sample_n(1000) |>
vis_dat()
-flights \%>\%
- slice(1:1000) \%>\%
+flights |>
+ slice(1:1000) |>
vis_dat()
}
diff --git a/man/vis_expect.Rd b/man/vis_expect.Rd
index 645a465..55bd490 100644
--- a/man/vis_expect.Rd
+++ b/man/vis_expect.Rd
@@ -9,10 +9,10 @@ vis_expect(data, expectation, show_perc = TRUE)
\arguments{
\item{data}{a data.frame}
-\item{expectation}{a formula following the syntax: \verb{~.x \{condition\}}.
-For example, writing \code{~.x < 20} would mean "where a variable value is less
-than 20, replace with NA", and \code{~.x \%in\% {vector}} would mean "where a
-variable has values that are in that vector".}
+\item{expectation}{a function, e.g., \verb{\\(x) \{condition\}}. For example, writing
+\verb{\\(x) x < 20} would mean "where a variable value is less than 20, replace
+with NA", and \code{\(x) \%in\% {vector}} would mean "where a variable has
+values that are in that vector".}
\item{show_perc}{logical. TRUE now adds in the \\% of expectations are
TRUE or FALSE in the whole dataset into the legend. Default value is TRUE.}
@@ -23,10 +23,10 @@ a ggplot2 object
\description{
\code{vis_expect} visualises certain conditions or values in your data. For
example, If you are not sure whether to expect -1 in your data, you could
-write: \code{vis_expect(data, ~.x == -1)}, and you can see if there are times
+write: \verb{vis_expect(data, \\(x) x == -1)}, and you can see if there are times
where the values in your data are equal to -1. You could also, for example,
explore a set of bad strings, or possible NA values and visualise where
-they are using \code{vis_expect(data, ~.x \%in\% bad_strings)} where
+they are using \code{vis_expect(data, \(x) x \%in\% bad_strings)} where
\code{bad_strings} is a character vector containing bad strings like \verb{N A}
\code{N/A} etc.
}
@@ -40,9 +40,9 @@ dat_test <- tibble::tribble(
NA, NA
)
-vis_expect(dat_test, ~.x == -1)
+vis_expect(dat_test, \(x) x == -1)
-vis_expect(airquality, ~.x == 5.1)
+vis_expect(airquality, \(x) x == 5.1)
# explore some common NA strings
@@ -62,7 +62,7 @@ dat_ms <- tibble::tribble(~x, ~y, ~z,
"N A", "E", -101,
"na", "F", -1)
-vis_expect(dat_ms, ~.x \%in\% common_nas)
+vis_expect(dat_ms, \(x) x \%in\% common_nas)
}
diff --git a/man/vis_miss.Rd b/man/vis_miss.Rd
index 6595493..85c4580 100644
--- a/man/vis_miss.Rd
+++ b/man/vis_miss.Rd
@@ -82,12 +82,12 @@ vis_miss(airquality, facet = Month)
# if you have a large dataset, you might want to try downsampling:
library(nycflights13)
library(dplyr)
-flights \%>\%
- sample_n(1000) \%>\%
+flights |>
+ sample_n(1000) |>
vis_miss()
-flights \%>\%
- slice(1:1000) \%>\%
+flights |>
+ slice(1:1000) |>
vis_miss()
}
diff --git a/man/vis_value.Rd b/man/vis_value.Rd
index 5c4a3da..a819734 100644
--- a/man/vis_value.Rd
+++ b/man/vis_value.Rd
@@ -33,8 +33,8 @@ vis_value(airquality, viridis_option = "C")
vis_value(airquality, viridis_option = "E")
\dontrun{
library(dplyr)
-diamonds \%>\%
- select_if(is.numeric) \%>\%
+diamonds |>
+ select_if(is.numeric) |>
vis_value()
}
}
diff --git a/man/visdat.Rd b/man/visdat.Rd
index cd9d6df..aa369ed 100644
--- a/man/visdat.Rd
+++ b/man/visdat.Rd
@@ -1,5 +1,5 @@
% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/visdat-package.r
+% Please edit documentation in R/visdat-package.R
\docType{package}
\name{visdat}
\alias{visdat-package}
@@ -38,6 +38,7 @@ Other contributors:
\item Earo Wang [contributor]
\item Nic Crane [contributor]
\item Christophe Regouby [contributor]
+ \item Jordi Rosell [contributor]
}
}
diff --git a/tests/testthat/_snaps/vis-expect.md b/tests/testthat/_snaps/vis-expect.md
index 9504aa3..4291721 100644
--- a/tests/testthat/_snaps/vis-expect.md
+++ b/tests/testthat/_snaps/vis-expect.md
@@ -1,7 +1,7 @@
# vis_expect fails when an object of the wrong class is provided
Code
- vis_expect(AirPassengers, ~ .x < 20)
+ vis_expect(AirPassengers, function(x) x < 20)
Condition
Error in `test_if_dataframe()`:
! `vis_dat()` requires a
diff --git a/tests/testthat/test-guess-type.R b/tests/testthat/test-guess-type.R
index c8870ce..5fb63a4 100644
--- a/tests/testthat/test-guess-type.R
+++ b/tests/testthat/test-guess-type.R
@@ -1,26 +1,28 @@
+# jarl-ignore-file true_false_symbol: vectors are deliberately bad
+# Date: 2026-08-12
test_that("guess_element correctly identifies individual elements", {
- expect_equal(guess_type(TRUE), "logical")
- expect_equal(guess_type(T), "logical")
- expect_equal(guess_type("TRUE"), "logical")
- expect_equal(guess_type("T"), "logical")
- expect_equal(guess_type("10"), "integer")
- expect_equal(guess_type(10), "integer")
- expect_equal(guess_type("10.1"), "double")
- expect_equal(guess_type(10.1), "double")
- expect_equal(guess_type("abc"), "character")
- expect_equal(guess_type("$%TG"), "character")
- expect_equal(guess_type(NA), NA_character_)
+ expect_identical(guess_type(TRUE), "logical")
+ expect_identical(guess_type(TRUE), "logical")
+ expect_identical(guess_type("TRUE"), "logical")
+ expect_identical(guess_type("T"), "logical")
+ expect_identical(guess_type("10"), "integer")
+ expect_identical(guess_type(10), "integer")
+ expect_identical(guess_type("10.1"), "double")
+ expect_identical(guess_type(10.1), "double")
+ expect_identical(guess_type("abc"), "character")
+ expect_identical(guess_type("$%TG"), "character")
+ expect_identical(guess_type(NA), NA_character_)
})
test_that("guess_element correctly identifies individual list elements", {
- expect_equal(guess_type(list(TRUE)), "logical")
- expect_equal(guess_type(list(T)), "logical")
- expect_equal(guess_type(list("TRUE")), "logical")
- expect_equal(guess_type(list("T")), "logical")
- expect_equal(guess_type(list("10")), "integer")
- expect_equal(guess_type(list(10)), "integer")
- expect_equal(guess_type(list("10.1")), "double")
- expect_equal(guess_type(list(10.1)), "double")
- expect_equal(guess_type(list("abc")), "character")
- expect_equal(guess_type(list("$%TG")), "character")
- expect_equal(guess_type(list(NA)), NA_character_)
+ expect_identical(guess_type(list(TRUE)), "logical")
+ expect_identical(guess_type(list(TRUE)), "logical")
+ expect_identical(guess_type(list("TRUE")), "logical")
+ expect_identical(guess_type(list("T")), "logical")
+ expect_identical(guess_type(list("10")), "integer")
+ expect_identical(guess_type(list(10)), "integer")
+ expect_identical(guess_type(list("10.1")), "double")
+ expect_identical(guess_type(list(10.1)), "double")
+ expect_identical(guess_type(list("abc")), "character")
+ expect_identical(guess_type(list("$%TG")), "character")
+ expect_identical(guess_type(list(NA)), NA_character_)
})
diff --git a/tests/testthat/test-vis-cor.R b/tests/testthat/test-vis-cor.R
index a947a69..cf9563f 100644
--- a/tests/testthat/test-vis-cor.R
+++ b/tests/testthat/test-vis-cor.R
@@ -1,3 +1,4 @@
+library(dplyr)
# try out all the options
vis_cor_plot <- vis_cor(airquality)
@@ -29,9 +30,8 @@ test_that("vis_cor works with facetting", {
vdiffr::expect_doppelganger("vis_cor_facet", vis_cor_facet)
})
-library(dplyr)
the_vis_cor_data <- data_vis_cor(airquality)
-the_vis_cor_data_month <- airquality %>% group_by(Month) %>% data_vis_cor()
+the_vis_cor_data_month <- airquality |> group_by(Month) |> data_vis_cor()
test_that("data_vis_cor gets the data properly", {
expect_type(the_vis_cor_data, "list")
diff --git a/tests/testthat/test-vis-dat.R b/tests/testthat/test-vis-dat.R
index b82c199..6ebaef0 100644
--- a/tests/testthat/test-vis-dat.R
+++ b/tests/testthat/test-vis-dat.R
@@ -1,3 +1,4 @@
+library(dplyr)
# try out all the options
vis_dat_plot <- vis_dat(typical_data)
vis_dat_plot_sort_type <- vis_dat(typical_data, sort_type = FALSE)
@@ -45,9 +46,8 @@ test_that("vis_dat works with facetting", {
vdiffr::expect_doppelganger("vis_dat_facet", vis_dat_facet)
})
-library(dplyr)
the_vis_dat_data <- data_vis_dat(airquality)
-the_vis_dat_data_month <- airquality %>% group_by(Month) %>% data_vis_dat()
+the_vis_dat_data_month <- airquality |> group_by(Month) |> data_vis_dat()
test_that("data_vis_dat gets the data properly", {
expect_type(the_vis_dat_data, "list")
diff --git a/tests/testthat/test-vis-expect.R b/tests/testthat/test-vis-expect.R
index c0edcad..fb31176 100644
--- a/tests/testthat/test-vis-expect.R
+++ b/tests/testthat/test-vis-expect.R
@@ -8,10 +8,10 @@ dat_test <- tibble::tribble(
# try out all the options
-vis_expect_plot <- vis_expect(dat_test, ~ .x == -1)
+vis_expect_plot <- vis_expect(dat_test, \(x) x == -1)
vis_expect_plot_show_perc_true <- vis_expect(
dat_test,
- ~ .x == -1,
+ \(x) x == -1,
show_perc = FALSE
)
@@ -28,6 +28,6 @@ test_that("vis_expect creates the right plot", {
test_that("vis_expect fails when an object of the wrong class is provided", {
expect_snapshot(
error = TRUE,
- vis_expect(AirPassengers, ~ .x < 20)
+ vis_expect(AirPassengers, \(x) x < 20)
)
})
diff --git a/tests/testthat/test-vis-large.R b/tests/testthat/test-vis-large.R
index fb63209..0cf7889 100644
--- a/tests/testthat/test-vis-large.R
+++ b/tests/testthat/test-vis-large.R
@@ -1,5 +1,5 @@
set.seed(2019 - 04 - 03 - 1104)
-big_df <- matrix(rnorm(100000), nrow = 1000, ncol = 1000) %>%
+big_df <- matrix(rnorm(100000), nrow = 1000, ncol = 1000) |>
as.data.frame()
test_that("vis_dat and vis_miss throw warnings when the DF is above size", {
diff --git a/tests/testthat/test-vis-miss.R b/tests/testthat/test-vis-miss.R
index 6b63f93..a0c5113 100644
--- a/tests/testthat/test-vis-miss.R
+++ b/tests/testthat/test-vis-miss.R
@@ -1,3 +1,4 @@
+library(dplyr)
# try out all the options
vis_miss_plot <- vis_miss(typical_data)
vis_miss_plot_cluster <- vis_miss(typical_data, cluster = TRUE)
@@ -30,8 +31,7 @@ test_that("vis_miss fails when an object of the wrong class is provided", {
)
})
-library(dplyr)
-star_wars_missings <- starwars %>%
+star_wars_missings <- starwars |>
select(-name, -skin_color, -eye_color, -films)
vis_miss_list <- vis_miss(star_wars_missings)
vis_miss_list_sort_rows <- vis_miss(starwars, sort_miss = TRUE)
@@ -67,7 +67,7 @@ test_that("vis_miss works with facets", {
})
the_vis_miss_data <- data_vis_miss(airquality)
-the_vis_miss_data_month <- airquality %>% group_by(Month) %>% data_vis_miss()
+the_vis_miss_data_month <- airquality |> group_by(Month) |> data_vis_miss()
test_that("data_vis_miss gets the data properly", {
expect_type(the_vis_miss_data, "list")
diff --git a/tests/testthat/test-visdat-internals.R b/tests/testthat/test-visdat-internals.R
index 0f5c783..5601518 100644
--- a/tests/testthat/test-visdat-internals.R
+++ b/tests/testthat/test-visdat-internals.R
@@ -1,22 +1,5 @@
-test_vis_gather_ <- vis_gather_(typical_data)
-
-suppressWarnings(
- test_old_gather <- typical_data %>%
- dplyr::mutate(rows = seq_len(nrow(.))) %>%
- tidyr::gather_(
- key_col = "variable",
- value_col = "valueType",
- gather_cols = names(.)[-length(.)]
- ) %>%
- dplyr::arrange(rows, variable, valueType)
-)
-
-test_that("vis_gather_ returns the same as previous", {
- expect_equal(test_vis_gather_, test_old_gather)
-})
-
-d_old <- typical_data %>%
- fingerprint_df() %>%
+d_old <- typical_data |>
+ fingerprint_df() |>
vis_gather_()
suppressWarnings({
@@ -27,35 +10,30 @@ suppressWarnings({
names(typical_data)
)$value
- d_old <- d_old %>% dplyr::arrange(value)
+ d_old <- d_old |> dplyr::arrange(value)
})
d_new <-
- typical_data %>%
- fingerprint_df() %>%
- vis_gather_() %>%
- dplyr::mutate(value = vis_extract_value_(typical_data)) %>%
+ typical_data |>
+ fingerprint_df() |>
+ vis_gather_() |>
+ dplyr::mutate(value = vis_extract_value_(typical_data)) |>
dplyr::arrange(value)
# get the values here so plotly can make them visible
test_that("vis_extract_value performs the same as old method", {
- expect_equal(d_old$value, d_new$value)
+ expect_identical(d_old$value, d_new$value)
})
-test_that("any_numeric returns TRUE for numeric dataframes and FALSE for dataframes containing non-numeric values", {
- expect_equal(all_numeric(airquality), TRUE)
- expect_equal(all_numeric(iris), FALSE)
+test_that("any_numeric returns TRUE for numeric dataframes and FALSE for \\
+ dataframes containing non-numeric values", {
+ expect_true(all_numeric(airquality))
+ expect_false(all_numeric(iris))
})
test_that("fingerprint can deal with complete-cases list columns", {
- expect_equal(
- all(visdat:::fingerprint(dplyr::starwars$films) %>% is.na()),
- FALSE
- )
+ expect_false(all(fingerprint(dplyr::starwars$films) |> is.na()))
})
test_that("fingerprint can count n/a in list columns", {
- expect_equal(
- sum(visdat:::fingerprint(dplyr::starwars$vehicles) %>% is.na()),
- 76
- )
+ expect_identical(sum(fingerprint(dplyr::starwars$vehicles) |> is.na()), 76L)
})
diff --git a/tests/testthat/test-vismiss-legend.R b/tests/testthat/test-vismiss-legend.R
index ef88f64..24f2248 100644
--- a/tests/testthat/test-vismiss-legend.R
+++ b/tests/testthat/test-vismiss-legend.R
@@ -3,12 +3,12 @@ test_that("miss_guide_label works for exactly 0.1% missing", {
# 1 missing in 1000.
test_miss_1 <- c(1:999, NA)
- expect_equal(
+ expect_identical(
miss_guide_label(test_miss_1)$p_miss_lab,
glue::as_glue("Missing \n(0.1%)")
)
- expect_equal(
+ expect_identical(
miss_guide_label(test_miss_1)$p_pres_lab,
glue::as_glue("Present \n(99.9%)")
)
@@ -18,27 +18,33 @@ test_that("miss_guide_label works for < 0.1% missing", {
# 1 missing in 10,000. This should produce Missing < 0.1
test_miss_2 <- c(1:10000, NA)
- expect_equal(miss_guide_label(test_miss_2)$p_miss_lab, "Missing (< 0.1%)")
- expect_equal(miss_guide_label(test_miss_2)$p_pres_lab, "Present (> 99.9%)")
+ expect_identical(miss_guide_label(test_miss_2)$p_miss_lab, "Missing (< 0.1%)")
+ expect_identical(
+ miss_guide_label(test_miss_2)$p_pres_lab,
+ "Present (> 99.9%)"
+ )
})
test_that("miss_guide_label works for no missing", {
# no missings
- test_miss_3 <- c(1:10)
+ test_miss_3 <- 1:10
- expect_equal(miss_guide_label(test_miss_3)$p_miss_lab, "No Missing Values")
- expect_equal(miss_guide_label(test_miss_3)$p_pres_lab, "Present (100%)")
+ expect_identical(
+ miss_guide_label(test_miss_3)$p_miss_lab,
+ "No Missing Values"
+ )
+ expect_identical(miss_guide_label(test_miss_3)$p_pres_lab, "Present (100%)")
})
test_that("miss_guide_label works for some missings", {
#
test_miss_4 <- c(1:10, NA)
- expect_equal(
+ expect_identical(
readr::parse_number(miss_guide_label(test_miss_4)$p_miss_lab),
round(mean(is.na(test_miss_4)) * 100, 1)
)
- expect_equal(
+ expect_identical(
readr::parse_number(miss_guide_label(test_miss_4)$p_pres_lab),
100 - round(mean(is.na(test_miss_4)) * 100, 1)
)
diff --git a/vignettes/using_visdat.Rmd b/vignettes/using_visdat.Rmd
index 5c5a44b..ece7d20 100644
--- a/vignettes/using_visdat.Rmd
+++ b/vignettes/using_visdat.Rmd
@@ -10,7 +10,8 @@ vignette: >
---
```{r setup, echo = FALSE, include = FALSE}
-
+# jarl-ignore-file true_false_symbol: vectors are deliberately bad
+# Date: 2026-08-12
knitr::opts_chunk$set(fig.width = 5,
fig.height = 4)
@@ -159,7 +160,9 @@ Let's make some changes to the `chickwts`, and compare this new dataset.
```{r vis-compare-iris}
set.seed(2019-04-03-1107)
chickwts_diff <- chickwts
-chickwts_diff[sample(1:nrow(chickwts), 30),sample(1:ncol(chickwts), 2)] <- NA
+rows_to_na <- sample(seq_len(nrow(chickwts)), 30)
+cols_to_na <- sample(seq_len(ncol(chickwts)), 2)
+chickwts_diff[rows_to_na, cols_to_na] <- NA
vis_compare(chickwts_diff, chickwts)