Skip to content

Commit

Permalink
Address CRAN check errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgirard committed May 10, 2023
1 parent 3b3bb12 commit 69b2274
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 12 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Expand Up @@ -41,6 +41,7 @@ Imports:
purrr (>= 0.3.4),
Rcpp,
rlang (>= 0.4.11),
scales,
stats,
tibble (>= 3.0.0),
tidyr (>= 1.0.0)
Expand Down
28 changes: 22 additions & 6 deletions R/ssm_visualization.R
Expand Up @@ -534,22 +534,38 @@ html_render <- function(df, caption = NULL, align = "l", ...) {
}

# S3 Generic

#' Create a spider/radar plot of circumplex scores
#'
#' Create a spider/radar plot of circumplex scores, either from a data frame
#' containing scale scores or the result of \code{ssm_analyze()}.
#'
#' @param x A dataframe or ssm result object.
#' @param amin An optional number to set as the minimum amplitude (center of
#' circle). If set to `NULL`, will try to detect a reasonable value.
#' @param amax An optional number to set as the maximum amplitude (outer ring of
#' circle). If set set to `NULL`, will try to detect a reasonable value.
#' @param angle_labels An optional character vector to display outside the
#' circle at each angle. Must be the same length as the number of angles.
#' @param linewidth An optional width for the lines of the profile polygons.
#' @param pointsize An optional size for the points at the scale scores.
#' @param ... Arguments passed on (currently unused)
#' @export
ssm_plot_scores <- function(x, ...) {
UseMethod("ssm_plot_scores")
}

#' @method ssm_plot_scores circumplex_ssm
#' @export
ssm_plot_scores.circumplex_ssm <- function(.ssm_object,
ssm_plot_scores.circumplex_ssm <- function(x,
amin = NULL,
amax = NULL,
angle_labels = NULL,
linewidth = 1,
pointsize = 3) {

# Get scores from SSM object
scores <- .ssm_object$scores
scores <- x$scores
# Reshape scores for plotting
scores_long <- tidyr::pivot_longer(
scores,
Expand All @@ -558,7 +574,7 @@ ssm_plot_scores.circumplex_ssm <- function(.ssm_object,
values_to = "Score"
)
# Get angles from SSM object
angles <- .ssm_object$details$angles
angles <- x$details$angles
if (is.null(amin)) amin <- pretty_min(scores_long$Score)
if (is.null(amax)) amax <- pretty_max(scores_long$Score)
scores_long$Angle <- rep(angles, times = nrow(scores_long) / length(angles))
Expand Down Expand Up @@ -595,7 +611,7 @@ ssm_plot_scores.circumplex_ssm <- function(.ssm_object,

#' @method ssm_plot_scores data.frame
#' @export
ssm_plot_scores.data.frame <- function(.data,
ssm_plot_scores.data.frame <- function(x,
scales,
angles = octants(),
group = NULL,
Expand All @@ -606,11 +622,11 @@ ssm_plot_scores.data.frame <- function(.data,
pointsize = 3) {

if (!is_enquo(group)) {
.data$group <- "All"
x$group <- "All"
group <- "group"
}
# Get scores from SSM object
scores <- dplyr::select(.data, {{group}}, {{scales}})
scores <- dplyr::select(x, {{group}}, {{scales}})
# Reshape scores for plotting
scores_long <- tidyr::pivot_longer(
scores,
Expand Down
4 changes: 2 additions & 2 deletions R/utils.R
Expand Up @@ -66,7 +66,7 @@ pretty_max <- function(v) {
if (sum(match) >= 1) {
out <- options[match][[1]]
} else {
out <- amax
out <- amax * scalar
}
out
}
Expand All @@ -93,7 +93,7 @@ pretty_min <- function(v) {
candidates <- options[match]
out <- candidates[length(candidates)]
} else {
out <- amin
out <- amin * scalar
}
out
}
Expand Down
3 changes: 2 additions & 1 deletion R/zzz.R
Expand Up @@ -6,7 +6,8 @@ if (getRversion() >= "2.15.1") {
"a_est", "a_lci", "a_uci", "circ_dist", "d_est", "d_lci", "d_uci", "e_est",
"e_lci", "e_uci", "est", "fit_lci", "fit_uci", "fit_est", "key", "label", "lci",
"octants", "quartile", "uci", "value", "x_est", "x_lci", "x_uci", "y_est",
"y_lci", "y_uci", "Scale", "Score", "Parameter", "lnty", ".im", "Sample"
"y_lci", "y_uci", "Scale", "Score", "Parameter", "lnty", ".im", "Sample",
"px", "py"
)
)
}
30 changes: 30 additions & 0 deletions man/ssm_plot_scores.Rd

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

6 changes: 3 additions & 3 deletions tests/testthat/test-utils.R
Expand Up @@ -8,9 +8,9 @@ test_that("Percentages are converted to strings properly", {
test_that("pretty max outputs the correct values", {
expect_warning(pretty_max(NA))
expect_equal(pretty_max(0), 0.05)
expect_equal(pretty_max(1), 1.25)
expect_equal(pretty_max(2.4), 2.5)
expect_equal(pretty_max(5), 8)
expect_equal(pretty_max(1), 2)
expect_equal(pretty_max(2.4), 4)
expect_equal(pretty_max(5), 7.5)
})

test_that("angle convenience functions work", {
Expand Down

0 comments on commit 69b2274

Please sign in to comment.