Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check on dev-versions #470

Merged
merged 9 commits into from
Dec 13, 2024
Merged

Check on dev-versions #470

merged 9 commits into from
Dec 13, 2024

Conversation

strengejacke
Copy link
Member

No description provided.

@rempsyc
Copy link
Member

rempsyc commented Dec 10, 2024

Before the datawizard change:

packageVersion("report")
#> [1] '0.5.9.1'
packageVersion("datawizard")
#> [1] '0.13.0'
iris$grp <- sample(letters[1:3], nrow(iris), TRUE)
x <- report::report_sample(
  iris,
  by = c("Species", "grp"),
  select = c("Sepal.Length", "Sepal.Width")
)

Created on 2024-12-09 with reprex v2.1.1

After the datawizard change:

packageVersion("report")
#> [1] '0.5.9.1'
packageVersion("datawizard")
#> [1] '0.13.0.17'
iris$grp <- sample(letters[1:3], nrow(iris), TRUE)
x <- report::report_sample(
  iris,
  by = c("Species", "grp"),
  select = c("Sepal.Length", "Sepal.Width")
)
#> Error: Following variable(s) were not found: setosa.c
#>   Possibly misspelled?

Created on 2024-12-09 with reprex v2.1.1

@rempsyc
Copy link
Member

rempsyc commented Dec 10, 2024

The error comes from datawizard::data_rename():

data <- iris
data$grp <- sample(letters[1:3], nrow(data), TRUE)
by = c("Species", "grp")
select = c("Sepal.Length", "Sepal.Width")

centrality = "mean"
ci = NULL
ci_method = "wilson"
ci_correct = FALSE
weights = NULL
digits = 2
n = FALSE

variables <- colnames(data)
variables <- intersect(select, variables)
class(data) <- "data.frame"
# character to factor
data[] <- lapply(data, function(i) {
  if (is.character(i)) {
    i <- as.factor(i)
  }
  i
})
groups <- as.data.frame(lapply(data[by], factor))

result <- lapply(split(data[variables], groups), function(x) {
  x[by] <- NULL
  report:::.generate_descriptive_table(
    x,
    centrality,
    weights,
    digits,
    n,
    ci,
    ci_method,
    ci_correct
  )
})

old_names <- datawizard::data_unite(
  unique(groups),
  new_column = ".old_names",
  separator = "."
)[[".old_names"]]
new_names <- datawizard::data_unite(
  unique(groups),
  new_column = ".new_names",
  separator = ", "
)[[".new_names"]]

old_names
#> [1] "setosa.a"     "setosa.c"     "setosa.b"     "versicolor.b" "versicolor.c"
#> [6] "versicolor.a" "virginica.b"  "virginica.a"  "virginica.c"
new_names
#> [1] "setosa, a"     "setosa, c"     "setosa, b"     "versicolor, b"
#> [5] "versicolor, c" "versicolor, a" "virginica, b"  "virginica, a" 
#> [9] "virginica, c"

result <- datawizard::data_rename(result, select = old_names, replacement = new_names)
#> Error: Following variable(s) were not found: setosa.a
#>   Possibly misspelled?

names(result)[1]
#> [1] "setosa.a"

Created on 2024-12-09 with reprex v2.1.1

@rempsyc
Copy link
Member

rempsyc commented Dec 10, 2024

The reason seems to be that data_rename() searches for all the variables mentioned in select for each data frame of the list, but each name only appears once in their respective data frame. Therefore, some variables are bound to not be found.

@rempsyc
Copy link
Member

rempsyc commented Dec 13, 2024

Devel version of parameters is also generating new errors:

parameters '0.24.0'

packageVersion("parameters")
#> [1] '0.24.0'
df <- lme4::sleepstudy
set.seed(123)
df$mygrp <- sample.int(5, size = 180, replace = TRUE)
df$mysubgrp <- NA
for (i in 1:5) {
  filter_group <- df$mygrp == i
  df$mysubgrp[filter_group] <-
    sample.int(30, size = sum(filter_group), replace = TRUE)
}

set.seed(123)
m1 <- lme4::lmer(Reaction ~ Days + (1 + Days | Subject), data = df)

x <- report::report(m1)

Created on 2024-12-12 with reprex v2.1.1

parameters '0.24.0.3'

packageVersion("parameters")
#> [1] '0.24.0.3'
df <- lme4::sleepstudy
set.seed(123)
df$mygrp <- sample.int(5, size = 180, replace = TRUE)
df$mysubgrp <- NA
for (i in 1:5) {
  filter_group <- df$mygrp == i
  df$mysubgrp[filter_group] <-
    sample.int(30, size = sum(filter_group), replace = TRUE)
}

set.seed(123)
m1 <- lme4::lmer(Reaction ~ Days + (1 + Days | Subject), data = df)

report::report(m1)
#> There are more names in `pattern` than in `replacement`. The last 4
#>   names of `pattern` are not modified.
#> Error in UseMethod("interpret"): no applicable method for 'interpret' applied to an object of class "character"

# The error comes from `report_parameters()`
report::report_parameters(m1, include_intercept = FALSE)
#> There are more names in `pattern` than in `replacement`. The last 4
#>   names of `pattern` are not modified.
#> Error in UseMethod("interpret"): no applicable method for 'interpret' applied to an object of class "character"

Created on 2024-12-12 with reprex v2.1.1

@rempsyc
Copy link
Member

rempsyc commented Dec 13, 2024

For some reason the failing tests fail to detect the DESCRIPTION file

@rempsyc rempsyc self-requested a review December 13, 2024 01:02
@rempsyc rempsyc merged commit 39409c8 into main Dec 13, 2024
22 checks passed
@rempsyc rempsyc deleted the data_rename_changes branch December 13, 2024 01:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants