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

Try to fix warnings in examples and vignettes #310

Merged
merged 13 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@ Config/Needs/website:
rstudio/bslib,
r-lib/pkgdown,
easystats/easystatstemplate
Remotes: easystats/insight, easystats/bayestestR
Remotes: easystats/bayestestR
2 changes: 1 addition & 1 deletion R/plot.hdi.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
plot_title <- "Credible Interval (CI)"
}

if (!is.null(parms)) {

Check warning on line 35 in R/plot.hdi.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/plot.hdi.R,line=35,col=7,[if_not_else_linter] In a simple if/else statement, prefer `if (A) x else y` to the less-readable `if (!A) y else x`.
params <- parms
} else {
params <- NULL
Expand All @@ -59,13 +59,13 @@
data <- data[levels_order]
dataplot <- data.frame()
for (i in names(data)) {
if (!is.null(params)) {

Check warning on line 62 in R/plot.hdi.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/plot.hdi.R,line=62,col=11,[if_not_else_linter] In a simple if/else statement, prefer `if (A) x else y` to the less-readable `if (!A) y else x`.
dataplot <- rbind(
dataplot,
cbind(
.compute_densities_hdi(data[[i]], hdi = as.data.frame(x[x$Parameter == i, ]), name = i),
"Effects" = params$Effects[params$Parameter == i],

Check warning on line 67 in R/plot.hdi.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/plot.hdi.R,line=67,col=13,[keyword_quote_linter] Only quote named arguments to functions if necessary, i.e., if the name is not a valid R symbol (see ?make.names).
"Component" = params$Component[params$Parameter == i]

Check warning on line 68 in R/plot.hdi.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/plot.hdi.R,line=68,col=13,[keyword_quote_linter] Only quote named arguments to functions if necessary, i.e., if the name is not a valid R symbol (see ?make.names).
)
)
} else {
Expand Down Expand Up @@ -140,8 +140,8 @@

out <- .as.data.frame_density(stats::density(x))

out$HDI_low <- sapply(out$x, .classify_hdi, hdi$CI_low, c(100, 100 * hdi$CI))

Check warning on line 143 in R/plot.hdi.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/plot.hdi.R,line=143,col=18,[undesirable_function_linter] Function "sapply" is undesirable.
out$HDI_high <- sapply(out$x, .classify_hdi, rev(hdi$CI_high), c(rev(100 * hdi$CI), 100))

Check warning on line 144 in R/plot.hdi.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/plot.hdi.R,line=144,col=19,[undesirable_function_linter] Function "sapply" is undesirable.
out$fill <- as.factor(pmax(out$HDI_low, out$HDI_high))
out$height <- out$y
out$y <- name
Expand All @@ -149,7 +149,7 @@
levels(out$fill) <- sprintf("%s%%", levels(out$fill))

# normalize
out$height <- as.vector((out$height - min(out$height, na.rm = TRUE)) / diff(range(out$height, na.rm = TRUE), na.rm = TRUE))

Check warning on line 152 in R/plot.hdi.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/plot.hdi.R,line=152,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 125 characters.

out
}
Expand Down Expand Up @@ -199,7 +199,7 @@
#' library(bayestestR)
#' set.seed(123)
#' m <- suppressWarnings(stan_glm(Sepal.Length ~ Petal.Width * Species, data = iris, refresh = 0))
#' result <- hdi(m)
#' result <- bayestestR::hdi(m)
#' result
#' plot(result)
#'
Expand Down
4 changes: 3 additions & 1 deletion R/plot.parameters_brms_meta.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@

attr(dataplot, "summary") <- summary
attr(dataplot, "info") <- list(
"xlab" = "Standardized Mean Difference",

Check warning on line 62 in R/plot.parameters_brms_meta.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/plot.parameters_brms_meta.R,line=62,col=5,[keyword_quote_linter] Only quote named arguments to functions if necessary, i.e., if the name is not a valid R symbol (see ?make.names).
"ylab" = NULL,

Check warning on line 63 in R/plot.parameters_brms_meta.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/plot.parameters_brms_meta.R,line=63,col=5,[keyword_quote_linter] Only quote named arguments to functions if necessary, i.e., if the name is not a valid R symbol (see ?make.names).
"legend_fill" = NULL,

Check warning on line 64 in R/plot.parameters_brms_meta.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/plot.parameters_brms_meta.R,line=64,col=5,[keyword_quote_linter] Only quote named arguments to functions if necessary, i.e., if the name is not a valid R symbol (see ?make.names).
"legend_color" = NULL,
"title" = "Bayesian Meta-Analysis"
)
Expand Down Expand Up @@ -129,7 +129,9 @@
#' prior(normal(0, 1), class = Intercept),
#' prior(cauchy(0, 0.5), class = sd)
#' )
#' model <- brm(yi | se(vi) ~ 1 + (1 | author), data = dat)
#' model <- suppressWarnings(
#' brm(yi | se(vi) ~ 1 + (1 | author), data = dat)
#' )
#'
#' # result
#' mp <- model_parameters(model)
Expand Down
4 changes: 3 additions & 1 deletion R/plot.parameters_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,9 @@ plot.see_parameters_model <- function(x,
} else if (has_response) {
p <- p + facet_wrap(~Response, ncol = n_columns, scales = facet_scales)
} else if (has_subgroups) {
suppressWarnings(p <- p + facet_grid(Subgroup ~ ., scales = "free", space = "free")) # nolint
suppressWarnings({
p <- p + facet_grid(Subgroup ~ ., scales = "free", space = "free")
})
}

if (length(model_attributes$parameter_names) > 1L) {
Expand Down
2 changes: 2 additions & 0 deletions R/plot.parameters_pca.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ data_plot.parameters_pca <- function(x, data = NULL, ...) {
title <- paste0("Rotated loadings from ", title, " (", rotation_name, ")")
}

# remove missing values in y, to avoid warning
dataplot <- dataplot[!is.na(dataplot$y), ]

attr(dataplot, "info") <- list(
"xlab" = "",
Expand Down
2 changes: 1 addition & 1 deletion R/plot.si.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#' library(bayestestR)
#' set.seed(123)
#' m <<- suppressWarnings(stan_glm(Sepal.Length ~ Petal.Width * Species, data = iris, refresh = 0))
#' result <- si(m)
#' result <- si(m, verbose = FALSE)
#' result
#' plot(result)
#'
Expand Down
9 changes: 4 additions & 5 deletions R/plot.visualisation_recipe.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ plot.see_visualisation_recipe <- function(x, ...) {
if (!"ggraph" %in% .packages()) {
attachNamespace("ggraph") # Needs to be attached
}
ggraph::ggraph(attributes(x)$data, layout = attributes(x)$layout) +
geoms_from_list(x)
suppressWarnings(ggraph::ggraph(attributes(x)$data, layout = attributes(x)$layout) + geoms_from_list(x))
} else {
ggplot2::ggplot(data = attributes(x)$data) +
geoms_from_list(x, ...)
suppressWarnings(ggplot2::ggplot(data = attributes(x)$data) +
geoms_from_list(x, ...))
}
}

Expand All @@ -23,7 +22,7 @@ plot.see_visualisation_recipe <- function(x, ...) {
plot.see_visualisation_recipes <- function(x, ...) {
the_plots <- list()
for (i in names(x)) {
the_plots[[i]] <- graphics::plot(x[[i]])
the_plots[[i]] <- suppressWarnings(graphics::plot(x[[i]]))
}
pw <- plots(the_plots, ...)
.safe_print_plots(pw)
Expand Down
4 changes: 2 additions & 2 deletions R/print.check_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ print.see_check_model <- function(x,
# to plot(), "type" is no longer recognized as "missing()"
plot_type <- attr(x, "type")

if (missing(type) && !is.null(plot_type) && plot_type %in% c("density", "discrete_dots", "discrete_interval", "discrete_both")) {
if (missing(type) && !is.null(plot_type) && plot_type %in% c("density", "discrete_dots", "discrete_interval", "discrete_both")) { # nolint
type <- plot_type
} else {
type <- match.arg(type, choices = c("density", "discrete_dots", "discrete_interval", "discrete_both"))
}

suppressWarnings(suppressMessages(plot(
suppressWarnings(suppressMessages(graphics::plot(
x,
style = style,
colors = colors,
Expand Down
6 changes: 4 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
return(x)
}


.as.data.frame_density <- function(x, ...) {
data.frame(x = x$x, y = x$y)
}


# safe conversion from factor to numeric
.factor_to_numeric <- function(x) {
if (is.numeric(x)) {
Expand All @@ -27,11 +29,13 @@
as.numeric(as.character(x))
}


.has_multiple_panels <- function(x) {
(!"Effects" %in% names(x) || insight::n_unique(x$Effects) <= 1L) &&
(!"Component" %in% names(x) || insight::n_unique(x$Component) <= 1L)
}


.clean_parameter_names <- function(params, grid = FALSE) {
params <- unique(params)
labels <- params
Expand Down Expand Up @@ -90,7 +94,6 @@
}



.fix_facet_names <- function(x) {
if ("Component" %in% names(x)) {
x$Component <- as.character(x$Component)
Expand All @@ -117,7 +120,6 @@
}



.intercept_names <-
c(
"(intercept)_zi",
Expand Down
2 changes: 1 addition & 1 deletion man/plot.see_hdi.Rd

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

4 changes: 3 additions & 1 deletion man/plot.see_parameters_brms_meta.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/plot.see_si.Rd

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

2 changes: 1 addition & 1 deletion vignettes/bayestestR.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ represent the density of the null at the value - the ratio of their heights is
the value of the Savage-Dickey Bayes factor:

```{r}
result <- bayesfactor_parameters(model)
result <- bayesfactor_parameters(model, verbose = FALSE)

result

Expand Down
8 changes: 7 additions & 1 deletion vignettes/modelbased.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,18 @@ plot(result)
```


```{r slopes-poly}
```{r slopes-poly, echo=TRUE, eval=FALSE}
model <- lm(Petal.Length ~ Species * poly(Sepal.Width, 3), data = iris)

result <- estimate_slopes(model, at = c("Sepal.Width", "Species"))
plot(result)
```
```{r slopes-poly2, eval=can_evaluate, echo=FALSE}
model <- lm(Petal.Length ~ Species * poly(Sepal.Width, 3), data = iris)

result <- estimate_slopes(model, at = c("Sepal.Width", "Species"))
suppressWarnings(print(plot(result)))
```

# Estimate derivatives

Expand Down
13 changes: 10 additions & 3 deletions vignettes/parameters.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ density estimation plots [from Bayesian
models](https://easystats.github.io/see/articles/bayestestR.html).

```{r}
result <- simulate_parameters(model1)
result <<- simulate_parameters(model1)

plot(result)
```
Expand Down Expand Up @@ -245,7 +245,12 @@ estimations](https://easystats.github.io/see/articles/bayestestR.html)).
# family = zero_inflated_poisson()
# )
brms_model <- insight::download_model("brms_zi_2")
result <- model_parameters(brms_model, effects = "all", component = "all")
result <- model_parameters(
brms_model,
effects = "all",
component = "all",
verbose = FALSE
)

plot(result)
```
Expand All @@ -255,7 +260,9 @@ plot(result)
```{r}
result <- model_parameters(brms_model,
effects = "all",
component = "all", group_level = TRUE
component = "all",
group_level = TRUE,
verbose = FALSE
)
plot(result)
```
Expand Down
Loading