Skip to content

Commit

Permalink
Merge branch 'main' into strengejacke/issue441
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke authored Nov 24, 2024
2 parents 185cd10 + 2741cdc commit 30e7adf
Show file tree
Hide file tree
Showing 194 changed files with 5,543 additions and 2,190 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ references.bib
^CRAN-SUBMISSION$
docs
^.dev$
^vignettes/s.
^vignettes/t.
12 changes: 12 additions & 0 deletions .dev/test-value_at.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
test_that("value_at", {
data(efc, package = "datawizard")
expect_equal(value_at(efc$e42dep, 5), 4, ignore_attr = TRUE)
expect_equal(value_at(efc$c12hour, 4), NA_real_, ignore_attr = TRUE)
expect_equal(value_at(efc$c12hour, 4, remove_na = TRUE), 168, ignore_attr = TRUE)
expect_equal(value_at(efc$c12hour, 5:7), efc$c12hour[5:7], ignore_attr = TRUE)
expect_equal(value_at(efc$e42dep, 123456, default = 55), 55, ignore_attr = TRUE)
expect_null(value_at(efc$e42dep, 123456))
expect_null(value_at(efc$e42dep, NULL))
expect_error(value_at(efc$e42dep, NA), regex = "`position` can't")
expect_error(value_at(efc$e42dep, c(3, NA)), regex = "`position` can't")
})
52 changes: 52 additions & 0 deletions .dev/value_at.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#' @title Find the value(s) at a specific position in a variable
#' @name value_at
#'
#' @description This function can be used to extract one or more values at a
#' specific position in a variable.
#'
#' @param x A vector or factor.
#' @param position An integer or a vector of integers, indicating the position(s)
#' of the value(s) to be returned. Negative values are counted from the end of
#' the vector. If `NA`, an error is thrown.
#' @param remove_na Logical, if `TRUE`, missing values are removed before
#' computing the position. If `FALSE`, missing values are included in the
#' computation.
#' @param default The value to be returned if the position is out of range.
#'
#' @seealso `data_summary()` to use `value_at()` inside a `data_summary()` call.
#'
#' @return A vector with the value(s) at the specified position(s).
#'
#' @examples
#' data(mtcars)
#' # 5th value
#' value_at(mtcars$mpg, 5)
#' # last value
#' value_at(mtcars$mpg, -1)
#' # out of range, return default
#' value_at(mtcars$mpg, 150)
#' # return 2nd and fifth value
#' value_at(mtcars$mpg, c(2, 5))
#' @export
value_at <- function(x, position = 1, default = NULL, remove_na = FALSE) {
if (remove_na) {
x <- x[!is.na(x)]
}
n <- length(x)
unlist(lapply(position, .values_at, x = x, n = n, default = default), use.names = FALSE)
}

# helper ----

.values_at <- function(x, position, n, default) {
if (is.na(position)) {
insight::format_error("`position` can't be `NA`.")
}
if (position < 0L) {
position <- position + n + 1
}
if (position <= 0 || position > n) {
return(default)
}
x[position]
}
15 changes: 0 additions & 15 deletions .github/workflows/R-CMD-check-strict.yaml

This file was deleted.

19 changes: 11 additions & 8 deletions .lintr
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
linters: linters_with_defaults(
linters: all_linters(
absolute_path_linter = NULL,
assignment_linter = NULL,
commented_code_linter = NULL,
cyclocomp_linter = cyclocomp_linter(25),
extraction_operator_linter = NULL,
cyclocomp_linter(25L),
if_not_else_linter(exceptions = character(0L)),
implicit_integer_linter = NULL,
line_length_linter(120),
library_call_linter = NULL,
line_length_linter(120L),
namespace_linter = NULL,
nonportable_path_linter = NULL,
object_name_linter = NULL,
object_length_linter(50),
object_length_linter(50L),
object_usage_linter = NULL,
todo_comment_linter = NULL,
undesirable_function_linter(c("mapply" = NA, "sapply" = NA, "setwd" = NA)),
string_boundary_linter = NULL,
strings_as_factors_linter = NULL,
undesirable_function_linter = NULL,
undesirable_operator_linter = NULL,
if_not_else_linter(exceptions = character(0L)),
unnecessary_concatenation_linter(allow_single_expression = FALSE),
defaults = linters_with_tags(tags = NULL)
unused_import_linter = NULL
)
46 changes: 22 additions & 24 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
Type: Package
Package: datawizard
Title: Easy Data Wrangling and Statistical Transformations
Version: 0.9.1.4
Version: 0.13.0.13
Authors@R: c(
person("Indrajeet", "Patil", , "[email protected]", role = "aut",
comment = c(ORCID = "0000-0003-1995-6531", Twitter = "@patilindrajeets")),
comment = c(ORCID = "0000-0003-1995-6531")),
person("Etienne", "Bacher", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-9271-5075")),
person("Dominique", "Makowski", , "[email protected]", role = "aut",
comment = c(ORCID = "0000-0001-5375-9967", Twitter = "@Dom_Makowski")),
comment = c(ORCID = "0000-0001-5375-9967")),
person("Daniel", "Lüdecke", , "[email protected]", role = "aut",
comment = c(ORCID = "0000-0002-8895-3206", Twitter = "@strengejacke")),
comment = c(ORCID = "0000-0002-8895-3206")),
person("Mattan S.", "Ben-Shachar", , "[email protected]", role = "aut",
comment = c(ORCID = "0000-0002-4287-4801")),
person("Brenton M.", "Wiernik", , "[email protected]", role = "aut",
comment = c(ORCID = "0000-0001-9560-6336", Twitter = "@bmwiernik")),
comment = c(ORCID = "0000-0001-9560-6336")),
person("Rémi", "Thériault", , "[email protected]", role = "ctb",
comment = c(ORCID = "0000-0003-4315-6788", Twitter = "@rempsyc")),
comment = c(ORCID = "0000-0003-4315-6788")),
person("Thomas J.", "Faulkenberry", , "[email protected]", role = "rev"),
person("Robert", "Garrett", , "[email protected]", role = "rev")
)
Maintainer: Etienne Bacher <[email protected]>
Description: A lightweight package to assist in key steps involved in any data
analysis workflow: (1) wrangling the raw data to get it in the needed form,
(2) applying preprocessing steps and statistical transformations, and
(3) compute statistical summaries of data properties and distributions.
Description: A lightweight package to assist in key steps involved in any data
analysis workflow: (1) wrangling the raw data to get it in the needed form,
(2) applying preprocessing steps and statistical transformations, and
(3) compute statistical summaries of data properties and distributions.
It is also the data wrangling backend for packages in 'easystats' ecosystem.
References: Patil et al. (2022) <doi:10.21105/joss.04684>.
License: MIT + file LICENSE
Expand All @@ -33,49 +33,47 @@ BugReports: https://github.com/easystats/datawizard/issues
Depends:
R (>= 3.6)
Imports:
insight (>= 0.19.8),
insight (>= 0.20.5),
stats,
utils
Suggests:
Suggests:
bayestestR,
boot,
brms,
curl,
data.table,
dplyr (>= 1.0),
dplyr (>= 1.1),
effectsize,
emmeans,
gamm4,
ggplot2,
ggplot2 (>= 3.5.0),
gt,
haven,
htmltools,
httr,
knitr,
lme4,
mediation,
parameters (>= 0.20.3),
poorman (>= 0.2.6),
modelbased,
parameters (>= 0.21.7),
poorman (>= 0.2.7),
psych,
readxl,
readr,
rio,
rmarkdown,
rstanarm,
see,
testthat (>= 3.2.0),
testthat (>= 3.2.1),
tibble,
tidyr,
withr
VignetteBuilder:
VignetteBuilder:
knitr
Encoding: UTF-8
Language: en-US
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Config/testthat/edition: 3
Config/testthat/parallel: true
Config/Needs/website:
rstudio/bslib,
r-lib/pkgdown,
easystats/easystatstemplate
Config/Needs/website: easystats/easystatstemplate
Remotes: easystats/insight
42 changes: 25 additions & 17 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Generated by roxygen2: do not edit by hand

S3method(as.data.frame,datawizard_crosstabs)
S3method(as.data.frame,datawizard_tables)
S3method(as.double,parameters_kurtosis)
S3method(as.double,parameters_skewness)
S3method(as.double,parameters_smoothness)
Expand Down Expand Up @@ -52,6 +54,10 @@ S3method(data_modify,data.frame)
S3method(data_modify,default)
S3method(data_modify,grouped_df)
S3method(data_peek,data.frame)
S3method(data_summary,data.frame)
S3method(data_summary,default)
S3method(data_summary,grouped_df)
S3method(data_summary,matrix)
S3method(data_tabulate,data.frame)
S3method(data_tabulate,default)
S3method(data_tabulate,grouped_df)
Expand All @@ -65,9 +71,9 @@ S3method(describe_distribution,grouped_df)
S3method(describe_distribution,list)
S3method(describe_distribution,numeric)
S3method(format,data_codebook)
S3method(format,datawizard_crosstab)
S3method(format,datawizard_table)
S3method(format,dw_data_peek)
S3method(format,dw_data_tabulate)
S3method(format,dw_data_xtabulate)
S3method(format,dw_groupmeans)
S3method(format,parameters_distribution)
S3method(kurtosis,data.frame)
Expand All @@ -89,11 +95,12 @@ S3method(normalize,numeric)
S3method(plot,visualisation_recipe)
S3method(print,data_codebook)
S3method(print,data_seek)
S3method(print,datawizard_crosstab)
S3method(print,datawizard_crosstabs)
S3method(print,datawizard_table)
S3method(print,datawizard_tables)
S3method(print,dw_data_peek)
S3method(print,dw_data_tabulate)
S3method(print,dw_data_tabulates)
S3method(print,dw_data_xtabulate)
S3method(print,dw_data_xtabulates)
S3method(print,dw_data_summary)
S3method(print,dw_groupmeans)
S3method(print,dw_groupmeans_list)
S3method(print,dw_transformer)
Expand All @@ -102,16 +109,16 @@ S3method(print,parameters_kurtosis)
S3method(print,parameters_skewness)
S3method(print,visualisation_recipe)
S3method(print_html,data_codebook)
S3method(print_html,datawizard_crosstab)
S3method(print_html,datawizard_crosstabs)
S3method(print_html,datawizard_table)
S3method(print_html,datawizard_tables)
S3method(print_html,dw_data_peek)
S3method(print_html,dw_data_tabulate)
S3method(print_html,dw_data_tabulates)
S3method(print_html,dw_data_xtabulate)
S3method(print_html,dw_data_xtabulates)
S3method(print_md,data_codebook)
S3method(print_md,datawizard_crosstab)
S3method(print_md,datawizard_table)
S3method(print_md,datawizard_tables)
S3method(print_md,dw_data_peek)
S3method(print_md,dw_data_tabulate)
S3method(print_md,dw_data_tabulates)
S3method(print_md,dw_data_xtabulate)
S3method(ranktransform,data.frame)
S3method(ranktransform,factor)
S3method(ranktransform,grouped_df)
Expand Down Expand Up @@ -213,7 +220,6 @@ export(assign_labels)
export(categorize)
export(center)
export(centre)
export(change_code)
export(change_scale)
export(coef_var)
export(coerce_to_numeric)
Expand All @@ -230,7 +236,6 @@ export(data_codebook)
export(data_duplicated)
export(data_extract)
export(data_filter)
export(data_find)
export(data_group)
export(data_join)
export(data_match)
Expand All @@ -244,11 +249,13 @@ export(data_remove)
export(data_rename)
export(data_rename_rows)
export(data_reorder)
export(data_replicate)
export(data_restoretype)
export(data_rotate)
export(data_seek)
export(data_select)
export(data_separate)
export(data_summary)
export(data_tabulate)
export(data_to_long)
export(data_to_wide)
Expand All @@ -265,9 +272,8 @@ export(distribution_coef_var)
export(distribution_mode)
export(empty_columns)
export(empty_rows)
export(extract_column_names)
export(find_columns)
export(format_text)
export(get_columns)
export(kurtosis)
export(labels_to_levels)
export(mean_sd)
Expand All @@ -290,7 +296,9 @@ export(reshape_longer)
export(reshape_wider)
export(reverse)
export(reverse_scale)
export(row_count)
export(row_means)
export(row_sums)
export(row_to_colnames)
export(rowid_as_column)
export(rownames_as_column)
Expand Down
Loading

0 comments on commit 30e7adf

Please sign in to comment.