Skip to content

Commit

Permalink
Fix tests for cran (#418)
Browse files Browse the repository at this point in the history
Co-authored-by: Joseph <[email protected]>
Co-authored-by: Barret Schloerke <[email protected]>
  • Loading branch information
3 people committed Jun 19, 2021
1 parent 4b37d1e commit 01a2c67
Show file tree
Hide file tree
Showing 18 changed files with 65 additions and 35 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@ jobs:
fail-fast: false
matrix:
config:
# - { os: macOS-latest, r: 'devel', force_suggests: "0" }
- { os: windows-latest, r: 'devel', force_suggests: "1" }
- { os: macOS-latest, r: 'devel', force_suggests: "0" }
# - { os: window-latest, r: 'devel', force_suggests: "1" }

- { os: macOS-latest, r: 'release', force_suggests: "1" }
- { os: windows-latest, r: 'release', force_suggests: "1" }
- { os: ubuntu-16.04, r: 'release', force_suggests: "1", rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest" }
- { os: ubuntu-20.04, r: 'release', force_suggests: "1", rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest" }

- { os: macOS-latest, r: 'oldrel', force_suggests: "1" }
- { os: windows-latest, r: 'oldrel', force_suggests: "1" }
- { os: ubuntu-16.04, r: 'oldrel', force_suggests: "1" , rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest" }
- { os: ubuntu-20.04, r: 'oldrel', force_suggests: "1" , rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest" }

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Description:
plot networks.
Depends:
R (>= 3.1),
ggplot2 (>= 3.3.0)
ggplot2 (>= 3.3.4)
Imports:
dplyr (>= 1.0.0),
forcats,
Expand Down Expand Up @@ -58,7 +58,7 @@ Suggests:
maps (>= 3.1.0),
mapproj,
nnet,
network (>= 1.12.0),
network (>= 1.17.1),
scagnostics,
sna (>= 2.3-2),
survival,
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# GGally (development version)

### Bug fixes

* Replace `ggplot2` usage of `*_guide = FALSE` with `*_guide = "none"` (@larmarange, #418)
* Require `network >= 1.17.1` (#418)

# GGally 2.1.1

### Bug fixes
Expand Down
2 changes: 1 addition & 1 deletion R/gg-plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@ ggally_text <- function(
if (!is.null(mapping$colour)) {
p <- p +
geom_text( label = label, mapping = mapping, ...) +
guides(colour = FALSE)
guides(colour = "none")
} else if ("colour" %in% names(aes(...))) {
p <- p +
geom_text( label = label, mapping = mapping, ...)
Expand Down
12 changes: 9 additions & 3 deletions R/ggcoef_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ ggcoef_compare <- function (
#' p_(ggcoef_multinom(mod, type = "faceted"))
#' p_(ggcoef_multinom(
#' mod, type = "faceted",
#' y.level = c(
#' y.level_label = c(
#' "pretty happy" = "pretty happy\n(ref: very happy)",
#' "very happy" = "very happy"
#' )
Expand Down Expand Up @@ -713,16 +713,22 @@ ggcoef_plot <- function (
)

if(!is.null(colour) && colour %in% names(data)) {
if (colour_guide)
if (colour_guide) {
colour_guide <- guide_legend()
} else {
colour_guide <- "none"
}
p <- p +
scale_colour_discrete(guide = colour_guide, labels = colour_labels) +
labs(colour = colour_lab)
}

if(!is.null(shape) && shape %in% names(data)) {
if (shape_guide)
if (shape_guide) {
shape_guide <- guide_legend()
} else {
shape_guide <- "none"
}
p <- p +
scale_shape_manual(
values = shape_values,
Expand Down
2 changes: 1 addition & 1 deletion R/ggcorr.R
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ ggcorr <- function(

p = p +
scale_size_continuous(range = c(min_size, max_size)) +
guides(size = FALSE)
guides(size = "none")

r = list(size = (min_size + max_size) / 2)

Expand Down
8 changes: 4 additions & 4 deletions R/ggnet2.R
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ ggnet2 <- function(
names(v_alpha) = unique(data$alpha)

p = p +
scale_alpha_manual("", values = v_alpha) + guides(alpha = FALSE)
scale_alpha_manual("", values = v_alpha) + guides(alpha = "none")

} else {

Expand Down Expand Up @@ -974,7 +974,7 @@ ggnet2 <- function(
names(v_color) = unique(data$color)

p = p +
scale_color_manual("", values = v_color) + guides(color = FALSE)
scale_color_manual("", values = v_color) + guides(color = "none")

}

Expand All @@ -986,7 +986,7 @@ ggnet2 <- function(
names(v_shape) = unique(data$shape)

p = p +
scale_shape_manual("", values = v_shape) + guides(shape = FALSE)
scale_shape_manual("", values = v_shape) + guides(shape = "none")

} else {

Expand All @@ -1009,7 +1009,7 @@ ggnet2 <- function(

v_size = as.numeric(names(v_size))
p = p +
scale_size_manual("", values = v_size) + guides(size = FALSE)
scale_size_manual("", values = v_size) + guides(size = "none")

} else {

Expand Down
5 changes: 4 additions & 1 deletion R/ggnetworkmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ if(getRversion() >= "2.15.1") {
#' )
#'
#' # convert to network
#' flights <- network(flights, directed = TRUE)
#' flights <- network(
#' flights[-114,], # remove loop
#' directed = TRUE
#' )
#'
#' # add geographic coordinates
#' flights %v% "lat" <- airports[ network.vertex.names(flights), "lat" ]
Expand Down
4 changes: 2 additions & 2 deletions R/ggsurv.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ if(getRversion() >= "2.15.1") {
#'
#' # Adjusting the legend of the ggsurv fit
#' p_(pl.sex +
#' ggplot2::guides(linetype = FALSE) +
#' ggplot2::guides(linetype = "none") +
#' ggplot2::scale_colour_discrete(
#' name = 'Sex',
#' breaks = c(1,2),
Expand Down Expand Up @@ -92,7 +92,7 @@ if(getRversion() >= "2.15.1") {
#' direction = 1
#' )(4)
#' ) +
#' ggplot2::guides(color = FALSE, linetype = FALSE))
#' ggplot2::guides(color = "none", linetype = "none"))
#' }
ggsurv <- function(
s,
Expand Down
2 changes: 1 addition & 1 deletion man/ggcoef_model.Rd

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

5 changes: 4 additions & 1 deletion man/ggnetworkmap.Rd

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

4 changes: 2 additions & 2 deletions man/ggsurv.Rd

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

2 changes: 1 addition & 1 deletion tests/testthat/test-gg-plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ test_that("dates", {
expect_equal(get("aes_params", envir = p$layers[[1]])$label, "Corr:\n0.278***")
p <- ggally_barDiag(nas, ggplot2::aes(x = date))
expect_equal(mapping_string(p$mapping$x), "date")
expect_equal(p$labels$y, "count")
expect_equal(as.character(p$labels$y), "count")

})

Expand Down
9 changes: 8 additions & 1 deletion tests/testthat/test-ggcoef_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ test_that("example of ggcoef_model", {
mod_simple <- lm(tip ~ day + time + total_bill, data = tips)
expect_print(ggcoef_model(mod_simple))

expect_warning(
print(
ggcoef_model(mod_simple, shape_guide = FALSE, colour_guide = FALSE)
),
NA
)

# custom variable labels
# you can use to define variable labels before computing model
if (require(labelled)) {
Expand Down Expand Up @@ -121,7 +128,7 @@ test_that("example of ggcoef_model", {
expect_print(ggcoef_multinom(mod, type = "faceted"))
expect_print(ggcoef_multinom(
mod, type = "faceted",
y.level = c(
y.level_label = c(
"pretty happy" = "pretty happy\n(ref: very happy)"
)
))
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-ggnet.R
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@ test_that("examples", {

# weighted bipartite network
bip <- network(
bip,
bip[-4,], # remove "loop"
matrix.type = "bipartite",
ignore.eval = FALSE,
names.eval = "weights"
ignore.eval = FALSE
# names.eval = "weights"
)

# test bipartite mode
Expand All @@ -223,7 +223,7 @@ test_that("examples", {
expect_warning(ggnet(network(matrix(1, nrow = 2, ncol = 2), loops = TRUE)), "self-loops")

expect_error(ggnet(1:2), "network object")
expect_error(ggnet(network(data.frame(1:2, 3:4), hyper = TRUE)), "hyper graphs")
expect_error(ggnet(network(data.frame(1:2, 3:4), hyper = TRUE)), "hyper")
expect_error(ggnet(network(data.frame(1:2, 3:4), multiple = TRUE)), "multiplex graphs")

### --- test igraph functionality
Expand Down
7 changes: 4 additions & 3 deletions tests/testthat/test-ggnet2.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ rq(RColorBrewer) # test ColorBrewer palettes
test_that("examples", {

### --- start: documented examples
set.seed(54321)

# random adjacency matrix
x <- 10
Expand Down Expand Up @@ -242,10 +243,10 @@ test_that("examples", {

# weighted bipartite network
bip <- network(
bip,
bip[-4, ], # remove loop
matrix.type = "bipartite",
ignore.eval = FALSE,
names.eval = "weights"
# names.eval = "weights"
)

# test bipartite mode
Expand All @@ -256,7 +257,7 @@ test_that("examples", {
expect_warning(ggnet2(network(matrix(1, nrow = 2, ncol = 2), loops = TRUE)), "self-loops")

expect_error(ggnet2(1:2), "network object")
expect_error(ggnet2(network(data.frame(1:2, 3:4), hyper = TRUE)), "hyper graphs")
expect_error(ggnet2(network(data.frame(1:2, 3:4), hyper = TRUE)), "hyper")
expect_error(ggnet2(network(data.frame(1:2, 3:4), multiple = TRUE)), "multiplex graphs")

### --- test igraph functionality
Expand Down
9 changes: 6 additions & 3 deletions tests/testthat/test-ggnetworkmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ skip_if_not_installed("geosphere")

# first 500 rows of http://datasets.flowingdata.com/tuts/maparcs/airports.csv
# avoids downloading the dataset to test the package
airports <- read.csv("data/airports.csv", header = TRUE)
airports <- read.csv(test_path("data/airports.csv"), header = TRUE)
rownames(airports) <- airports$iata

# select some random flights
Expand All @@ -31,7 +31,10 @@ flights <- data.frame(
)

# convert to network
flights <- network(flights, directed = TRUE)
flights <- network(
flights[-114,], # remove loop
directed = TRUE
)

# add geographic coordinates
flights %v% "lat" <- airports[ network.vertex.names(flights), "lat" ] # nolint
Expand Down Expand Up @@ -205,7 +208,7 @@ test_that("network coercion", {
)

expect_error(ggnetworkmap(net = 1:2), "network object")
expect_error(ggnetworkmap(net = network(data.frame(1:2, 3:4), hyper = TRUE)), "hyper graphs")
expect_error(ggnetworkmap(net = network(data.frame(1:2, 3:4), hyper = TRUE)), "hyper")
expect_error(
ggnetworkmap(net = network(data.frame(1:2, 3:4), multiple = TRUE)),
"multiplex graphs"
Expand Down
6 changes: 3 additions & 3 deletions vignettes/ggsurv.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ library(GGally)


This function produces Kaplan-Meier plots using `ggplot2`.
As a first argument, `ggsurv()` needs a `survival::survfit()` object.
As a first argument, `ggsurv()` needs a `survival::survfit()` object.
Default settings differ for single stratum and multiple strata objects.

## Single Stratum
Expand Down Expand Up @@ -57,7 +57,7 @@ Since a ggplot2 object is returned, plot objects may be altered after the origin

```{r ggsurv-legend}
pl.sex +
ggplot2::guides(linetype = FALSE) +
ggplot2::guides(linetype = "none") +
ggplot2::scale_colour_discrete(
name = 'Sex',
breaks = c(1, 2),
Expand Down Expand Up @@ -94,5 +94,5 @@ pl.kid +
direction = 1
)(4)
) +
ggplot2::guides(color = FALSE, linetype = FALSE)
ggplot2::guides(color = "none", linetype = "none")
```

0 comments on commit 01a2c67

Please sign in to comment.