Skip to content

Commit

Permalink
CRAN release 0.4.0 (#143)
Browse files Browse the repository at this point in the history
* update tests

* revert a few test changes

* prepare CRAN submission

* Update NEWS.md

* useful in other functions, but for now, in reshape only

* fix URL

* Delete .DS_Store

* remove png

Co-authored-by: Daniel <[email protected]>
  • Loading branch information
IndrajeetPatil and strengejacke authored Mar 30, 2022
1 parent c97eed4 commit 6d9331f
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 61 deletions.
6 changes: 2 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: datawizard
Title: Easy Data Wrangling
Version: 0.3.1.9010
Version: 0.4.0
Authors@R: c(
person("Dominique", "Makowski", , "[email protected]", role = "aut",
comment = c(ORCID = "0000-0001-5375-9967", Twitter = "@Dom_Makowski")),
Expand All @@ -25,7 +25,7 @@ BugReports: https://github.com/easystats/datawizard/issues
Depends:
R (>= 3.4)
Imports:
insight (>= 0.16.0.5),
insight (>= 0.17.0),
stats,
utils
Suggests:
Expand All @@ -46,8 +46,6 @@ Suggests:
see,
spelling,
testthat (>= 3.0.0)
Remotes:
easystats/insight
VignetteBuilder:
knitr
Config/testthat/edition: 3
Expand Down
64 changes: 32 additions & 32 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# datawizard 0.3.0.9000
# datawizard 0.4.0

MAJOR CHANGES

Expand All @@ -17,57 +17,57 @@ MAJOR CHANGES

NEW FUNCTIONS

* To convert rownames to a column, and *vice versa*: `rownames_as_column()`
and `column_as_rownames()` (@etiennebacher, #80).
* To convert rownames to a column, and *vice versa*: `rownames_as_column()`
and `column_as_rownames()` (@etiennebacher, #80).

* `find_columns()` and `get_columns()` to find column names or retrieve
subsets of data frames, based on various select-methods (including
select-helpers). These function will supersede `data_findcols()` in the
future.
* `find_columns()` and `get_columns()` to find column names or retrieve
subsets of data frames, based on various select-methods (including
select-helpers). These function will supersede `data_findcols()` in the
future.

* `data_filter()` as complement for `data_match()`, which works with logical
expressions for filtering rows of data frames.

* For computing weighted centrality measures and dispersion: `weighted_mean()`,
`weighted_median()`, `weighted_sd()` and `weighted_mad()`.
* For computing weighted centrality measures and dispersion: `weighted_mean()`,
`weighted_median()`, `weighted_sd()` and `weighted_mad()`.

* To replace `NA` in vectors and dataframes: `convert_na_to()` (@etiennebacher, #111).
* To replace `NA` in vectors and dataframes: `convert_na_to()` (@etiennebacher, #111).

MINOR CHANGES

* The `select` argument in several functions (like `data_remove()`,
`reshape_longer()`, or `data_extract()`) now allow the use of select-helpers
for selecting variables based on specific patterns.
* The `select` argument in several functions (like `data_remove()`,
`reshape_longer()`, or `data_extract()`) now allows the use of select-helpers
for selecting variables based on specific patterns.

* `data_extract()` gains new arguments to allow type-safe return values,
i.e. *always* return a vector *or* a data frame. Thus, `data_extract()`
can now be used to select multiple variables or pull a single variable
from data frames.
* `data_extract()` gains new arguments to allow type-safe return values,
i.e. *always* return a vector *or* a data frame. Thus, `data_extract()`
can now be used to select multiple variables or pull a single variable
from data frames.

* `data_match()` gains a `match` argument, to indicate with which logical
operation matching results should be combined.
* `data_match()` gains a `match` argument, to indicate with which logical
operation matching results should be combined.

* Improved support for *labelled data* for many functions, i.e. returned
data frame will preserve value and variable label attributes, where
possible and applicable.
* Improved support for *labelled data* for many functions, i.e. returned
data frame will preserve value and variable label attributes, where
possible and applicable.

* `describe_distribution()` now works with lists (@etiennebacher, #105).
* `describe_distribution()` now works with lists (@etiennebacher, #105).

* `data_rename()` doesn't use `pattern` anymore to rename the columns if
`replacement` is not provided (@etiennebacher, #103).
* `data_rename()` doesn't use `pattern` anymore to rename the columns if
`replacement` is not provided (@etiennebacher, #103).

* `data_rename()` now adds a suffix to duplicated names in `replacement`
(@etiennebacher, #103).
* `data_rename()` now adds a suffix to duplicated names in `replacement`
(@etiennebacher, #103).

BUG FIXES

* `data_to_numeric()` produced wrong results for factors when
`dummy_factors = TRUE` and factor contained missing values.
* `data_to_numeric()` produced wrong results for factors when
`dummy_factors = TRUE` and factor contained missing values.

* `data_match()` produced wrong results when data contained missing values.
* `data_match()` produced wrong results when data contained missing values.

* Fixed CRAN check issues in `data_extract()` when more than one variable
was extracted from a data frame.
* Fixed CRAN check issues in `data_extract()` when more than one variable
was extracted from a data frame.

# datawizard 0.3.0

Expand Down
10 changes: 9 additions & 1 deletion R/data_reshape.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ data_to_long <- function(data,
values_to = "Value",
rows_to = NULL,
ignore_case = FALSE,
regex = FALSE,
cols = select,
...,
names_to = colnames_to) {
Expand All @@ -100,7 +101,14 @@ data_to_long <- function(data,
}

# evaluate arguments
cols <- .select_nse(select, data, exclude = NULL, ignore_case, verbose = FALSE)
cols <- .select_nse(
select,
data,
exclude = NULL,
ignore_case = ignore_case,
regex = regex,
verbose = FALSE
)

# Sanity checks ----------------

Expand Down
2 changes: 1 addition & 1 deletion R/demean.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
#' A description of how to translate the
#' formulas described in *Bell et al. 2018* into R using `lmer()`
#' from \pkg{lme4} can be found in
#' [this vignette](https://easystats.github.io/datawizard/articles/demean.html).
#' [this vignette](https://easystats.github.io/parameters/articles/demean.html).
#' }
#'
#' @references
Expand Down
6 changes: 3 additions & 3 deletions R/weighted_mean_median_sd_mad.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ weighted_mean <- function(x, weights = NULL, verbose = TRUE, ...) {
#' @export
#' @rdname weighted_mean
weighted_median <- function(x, weights = NULL, verbose = TRUE, ...) {

if (!.are_weights(weights) || !.validate_weights(weights, verbose)) {
return(stats::median(x, na.rm = TRUE))
}
Expand All @@ -53,10 +52,11 @@ weighted_median <- function(x, weights = NULL, verbose = TRUE, ...) {
rw <- cumsum(weights) / sum(weights)
md.values <- min(which(rw >= p))

if (rw[md.values] == p)
if (rw[md.values] == p) {
q <- mean(x[md.values:(md.values + 1)])
else
} else {
q <- x[md.values]
}

q
}
Expand Down
2 changes: 0 additions & 2 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ template:
bslib:
primary: "#0054AD"
opengraph:
image:
src: man/figures/card.png
twitter:
creator: "@easystats4u"
card: summary_large_image
Expand Down
Binary file removed man/.DS_Store
Binary file not shown.
11 changes: 11 additions & 0 deletions man/data_to_long.Rd

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

2 changes: 1 addition & 1 deletion man/demean.Rd

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

Binary file removed man/figures/card.png
Binary file not shown.
12 changes: 6 additions & 6 deletions tests/testthat/_snaps/describe_distribution.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
Code
describe_distribution(factor(substring("statistics", 1:10, 1:10)))
Output
Mean | SD | Min | Max | Skewness | Kurtosis | n | n_Missing
------------------------------------------------------------
NA | NA | a | t | -0.77 | -0.13 | 10 | 0
Mean | SD | Range | Skewness | Kurtosis | n | n_Missing
---------------------------------------------------------
| | [a, t] | -0.77 | -0.13 | 10 | 0

# describe_distribution - character

Code
describe_distribution(as.character(ToothGrowth$supp))
Output
Mean | SD | Min | Max | Skewness | Kurtosis | n | n_Missing
------------------------------------------------------------
NA | NA | VC | OJ | 0 | -2.1 | 60 | 0
Mean | SD | Range | Skewness | Kurtosis | n | n_Missing
-----------------------------------------------------------
| | [VC, OJ] | 0 | -2.07 | 60 | 0

30 changes: 20 additions & 10 deletions tests/testthat/test-data_reshape.R
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,17 @@ test_that("data_reshape works as expected - complex dataset", {
})


test_that("data_reshape works as expected - simple dataset", {
d <- data.frame(
age = c(20, 30, 40),
sex = c("Female", "Male", "Male"),
score_t1 = c(30, 35, 32),
score_t2 = c(33, 34, 37),
speed_t1 = c(2, 3, 1),
speed_t2 = c(3, 4, 5),
stringsAsFactors = FALSE
)
d <- data.frame(
age = c(20, 30, 40),
sex = c("Female", "Male", "Male"),
score_t1 = c(30, 35, 32),
score_t2 = c(33, 34, 37),
speed_t1 = c(2, 3, 1),
speed_t2 = c(3, 4, 5),
stringsAsFactors = FALSE
)

test_that("data_reshape works as expected - simple dataset", {
out <- data_to_long(d, starts_with("score"))
expect_equal(out$Name, c("score_t1", "score_t2", "score_t1", "score_t2", "score_t1", "score_t2"))
expect_equal(out$Value, c(d$score_t1, d$score_t2)[c(1, 4, 2, 5, 3, 6)])
Expand All @@ -165,3 +165,13 @@ test_that("data_reshape works as expected - simple dataset", {
expect_equal(out$NewCol, c("score_t2", "speed_t2", "score_t2", "speed_t2", "score_t2", "speed_t2"))
expect_equal(out$Time, c(33, 3, 34, 4, 37, 5))
})


test_that("data_reshape works as expected - select-helper inside functions, using regex", {
test_fun <- function(data, i) {
data_to_long(data, select = i, regex = TRUE)
}
out <- test_fun(d, "^score")
expect_equal(out$Name, c("score_t1", "score_t2", "score_t1", "score_t2", "score_t1", "score_t2"))
expect_equal(out$Value, c(d$score_t1, d$score_t2)[c(1, 4, 2, 5, 3, 6)])
})
1 change: 1 addition & 0 deletions tests/testthat/test-distributions.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ test_that("distributions", {
skip_if_not_installed("bayestestR")
skip_if_not_installed("parameters")

set.seed(123)
x <- bayestestR::distribution_normal(100)

expect_equal(kurtosis(x)$Kurtosis, -0.3204763, tolerance = 0.01)
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-find_columns.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ test_that("find_columns works as expected", {
find_columns(iris, "Width$", regex = TRUE),
c("Sepal.Width", "Petal.Width")
)

})


Expand Down

0 comments on commit 6d9331f

Please sign in to comment.