From 6c1d359b35b289ef5d3f6ea4323672936c5beb56 Mon Sep 17 00:00:00 2001 From: Thomas Lin Pedersen Date: Tue, 7 Mar 2023 12:29:50 +0100 Subject: [PATCH] 2023 upkeep (#166) --- .../CODE_OF_CONDUCT.md | 50 +++++++++---------- .github/workflows/R-CMD-check.yaml | 19 +++---- .github/workflows/pkgdown.yaml | 4 +- .github/workflows/pr-commands.yaml | 4 +- .github/workflows/test-coverage.yaml | 23 ++++++++- DESCRIPTION | 7 +-- R/SVG.R | 22 +++++--- R/fonts.R | 19 ++++--- R/svglite-package.R | 6 +++ R/utils.R | 8 +-- README.Rmd | 11 ++-- README.md | 23 ++++----- tests/testthat.R | 8 +++ tests/testthat/test-clip.R | 2 - tests/testthat/test-colour.R | 1 - tests/testthat/test-devSVG.R | 11 ++-- tests/testthat/test-lines.R | 1 - tests/testthat/test-output.R | 2 - tests/testthat/test-path.R | 22 ++++---- tests/testthat/test-points.R | 2 - tests/testthat/test-raster.R | 1 - tests/testthat/test-rect.R | 1 - tests/testthat/test-scale.R | 13 +++-- tests/testthat/test-text-fonts.R | 8 ++- tests/testthat/test-text.R | 5 +- 25 files changed, 154 insertions(+), 119 deletions(-) rename CODE_OF_CONDUCT.md => .github/CODE_OF_CONDUCT.md (81%) create mode 100644 R/svglite-package.R diff --git a/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md similarity index 81% rename from CODE_OF_CONDUCT.md rename to .github/CODE_OF_CONDUCT.md index b36903f..3ac34c8 100644 --- a/CODE_OF_CONDUCT.md +++ b/.github/CODE_OF_CONDUCT.md @@ -6,8 +6,8 @@ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, -nationality, personal appearance, race, religion, or sexual identity and -orientation. +nationality, personal appearance, race, caste, color, religion, or sexual +identity and orientation. We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. @@ -21,25 +21,25 @@ community include: * Being respectful of differing opinions, viewpoints, and experiences * Giving and gracefully accepting constructive feedback * Accepting responsibility and apologizing to those affected by our mistakes, -and learning from the experience + and learning from the experience * Focusing on what is best not just for us as individuals, but for the overall -community + community Examples of unacceptable behavior include: -* The use of sexualized language or imagery, and sexual attention or -advances of any kind +* The use of sexualized language or imagery, and sexual attention or advances of + any kind * Trolling, insulting or derogatory comments, and personal or political attacks * Public or private harassment -* Publishing others' private information, such as a physical or email -address, without their explicit permission +* Publishing others' private information, such as a physical or email address, + without their explicit permission * Other conduct which could reasonably be considered inappropriate in a -professional setting + professional setting ## Enforcement Responsibilities -Community leaders are responsible for clarifying and enforcing our standards -of acceptable behavior and will take appropriate and fair corrective action in +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. @@ -50,17 +50,17 @@ decisions when appropriate. ## Scope -This Code of Conduct applies within all community spaces, and also applies -when an individual is officially representing the community in public spaces. -Examples of representing our community include using an official e-mail -address, posting via an official social media account, or acting as an appointed +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed representative at an online or offline event. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported to the community leaders responsible for enforcement at [INSERT CONTACT -METHOD]. All complaints will be reviewed and investigated promptly and fairly. +reported to the community leaders responsible for enforcement at codeofconduct@posit.co. +All complaints will be reviewed and investigated promptly and fairly. All community leaders are obligated to respect the privacy and security of the reporter of any incident. @@ -114,15 +114,13 @@ community. ## Attribution This Code of Conduct is adapted from the [Contributor Covenant][homepage], -version 2.0, -available at https://www.contributor-covenant.org/version/2/0/ -code_of_conduct.html. +version 2.1, available at +. -Community Impact Guidelines were inspired by [Mozilla's code of conduct -enforcement ladder](https://github.com/mozilla/diversity). - -[homepage]: https://www.contributor-covenant.org +Community Impact Guidelines were inspired by +[Mozilla's code of conduct enforcement ladder][https://github.com/mozilla/inclusion]. For answers to common questions about this code of conduct, see the FAQ at -https://www.contributor-covenant.org/faq. Translations are available at https:// -www.contributor-covenant.org/translations. +. Translations are available at . + +[homepage]: https://www.contributor-covenant.org diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 4efedd9..ee65ccb 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -22,26 +22,27 @@ jobs: fail-fast: false matrix: config: - - {os: macOS-latest, r: 'release'} + - {os: macos-latest, r: 'release'} - {os: windows-latest, r: 'release'} # Use 3.6 to trigger usage of RTools35 - {os: windows-latest, r: '3.6'} + # use 4.1 to check with rtools40's older compiler + - {os: windows-latest, r: '4.1'} - # Use older ubuntu to maximise backward compatibility - - {os: ubuntu-18.04, r: 'devel', http-user-agent: 'release'} - - {os: ubuntu-18.04, r: 'release'} - - {os: ubuntu-18.04, r: 'oldrel-1'} - - {os: ubuntu-18.04, r: 'oldrel-2'} - - {os: ubuntu-18.04, r: 'oldrel-3'} - - {os: ubuntu-18.04, r: 'oldrel-4'} + - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} + - {os: ubuntu-latest, r: 'release'} + - {os: ubuntu-latest, r: 'oldrel-1'} + - {os: ubuntu-latest, r: 'oldrel-2'} + - {os: ubuntu-latest, r: 'oldrel-3'} + - {os: ubuntu-latest, r: 'oldrel-4'} env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} R_KEEP_PKG_SOURCE: yes steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: r-lib/actions/setup-pandoc@v2 diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml index 0b26021..087f0b0 100644 --- a/.github/workflows/pkgdown.yaml +++ b/.github/workflows/pkgdown.yaml @@ -20,7 +20,7 @@ jobs: env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: r-lib/actions/setup-pandoc@v2 @@ -39,7 +39,7 @@ jobs: - name: Deploy to GitHub pages 🚀 if: github.event_name != 'pull_request' - uses: JamesIves/github-pages-deploy-action@4.1.4 + uses: JamesIves/github-pages-deploy-action@v4.4.1 with: clean: false branch: gh-pages diff --git a/.github/workflows/pr-commands.yaml b/.github/workflows/pr-commands.yaml index 97271eb..71f335b 100644 --- a/.github/workflows/pr-commands.yaml +++ b/.github/workflows/pr-commands.yaml @@ -14,7 +14,7 @@ jobs: env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: r-lib/actions/pr-fetch@v2 with: @@ -51,7 +51,7 @@ jobs: env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: r-lib/actions/pr-fetch@v2 with: diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index 4b65418..2c5bb50 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -15,7 +15,7 @@ jobs: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: r-lib/actions/setup-r@v2 with: @@ -27,5 +27,24 @@ jobs: needs: coverage - name: Test coverage - run: covr::codecov(quiet = FALSE) + run: | + covr::codecov( + quiet = FALSE, + clean = FALSE, + install_path = file.path(Sys.getenv("RUNNER_TEMP"), "package") + ) shell: Rscript {0} + + - name: Show testthat output + if: always() + run: | + ## -------------------------------------------------------------------- + find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true + shell: bash + + - name: Upload test results + if: failure() + uses: actions/upload-artifact@v3 + with: + name: coverage-test-failures + path: ${{ runner.temp }}/package diff --git a/DESCRIPTION b/DESCRIPTION index add774b..009f0a2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -17,7 +17,7 @@ Authors@R: c( comment = "Improved styles; polypath implementation"), person("Håkon", "Malmedal", role = "ctb", comment = "Opacity code"), - person("RStudio", role = c("cph", "fnd")) + person("Posit, PBC", role = c("cph", "fnd")) ) Description: A graphics device for R that produces 'Scalable Vector Graphics'. 'svglite' is a fork of the older 'RSvgDevice' package. @@ -25,7 +25,7 @@ License: GPL (>= 2) URL: https://svglite.r-lib.org, https://github.com/r-lib/svglite BugReports: https://github.com/r-lib/svglite/issues Depends: - R (>= 3.0.0) + R (>= 3.5.0) Imports: systemfonts (>= 1.0.0) Suggests: @@ -34,7 +34,7 @@ Suggests: htmltools, knitr, rmarkdown, - testthat, + testthat (>= 3.0.0), xml2 (>= 1.0.0) LinkingTo: cpp11, @@ -46,3 +46,4 @@ Encoding: UTF-8 Roxygen: list(markdown = TRUE) RoxygenNote: 7.2.1 SystemRequirements: C++11, libpng +Config/testthat/edition: 3 diff --git a/R/SVG.R b/R/SVG.R index ea303ca..e9098b8 100644 --- a/R/SVG.R +++ b/R/SVG.R @@ -69,7 +69,7 @@ #' @examples #' # Save to file #' svglite(tempfile("Rplots.svg")) -#' plot(1:11, (-5:5)^2, type = 'b', main = "Simple Example") +#' plot(1:11, (-5:5)^2, type = "b", main = "Simple Example") #' dev.off() #' #' @keywords device @@ -83,8 +83,9 @@ svglite <- function(filename = "Rplot%03d.svg", width = 10, height = 8, if (!missing(file)) { filename <- file } - if (invalid_filename(filename)) + if (invalid_filename(filename)) { stop("invalid 'file': ", filename) + } aliases <- validate_aliases(system_fonts, user_fonts) web_fonts <- validate_web_fonts(web_fonts) if (is.null(id)) { @@ -105,10 +106,13 @@ svglite <- function(filename = "Rplot%03d.svg", width = 10, height = 8, #' @return A function with no arguments: call the function to get the #' current value of the string. #' @examples -#' s <- svgstring(); s() +#' s <- svgstring() +#' s() #' -#' plot.new(); s(); -#' text(0.5, 0.5, "Hi!"); s() +#' plot.new() +#' s() +#' text(0.5, 0.5, "Hi!") +#' s() #' dev.off() #' #' s <- svgstring() @@ -130,13 +134,15 @@ svgstring <- function(width = 10, height = 8, bg = "white", id <- as.character(id) env <- new.env(parent = emptyenv()) - string_src <- svgstring_(env, width = width, height = height, bg = bg, + string_src <- svgstring_(env, + width = width, height = height, bg = bg, pointsize = pointsize, standalone = standalone, aliases = aliases, - webfonts = web_fonts, id = id, fix_text_size, scaling) + webfonts = web_fonts, id = id, fix_text_size, scaling + ) function() { svgstr <- env$svg_string - if(!env$is_closed) { + if (!env$is_closed) { svgstr <- c(svgstr, get_svg_content(string_src)) } structure(svgstr, class = "svg") diff --git a/R/fonts.R b/R/fonts.R index c365d89..7a1446b 100644 --- a/R/fonts.R +++ b/R/fonts.R @@ -52,9 +52,11 @@ validate_system_alias <- function(alias) { matched <- match_family(alias) if (alias != matched) { - warning(call. = FALSE, + warning( + call. = FALSE, "System font `", alias, "` not found. ", - "Closest match: `", matched, "`") + "Closest match: `", matched, "`" + ) } matched } @@ -68,7 +70,8 @@ is_user_alias <- function(x) { validate_user_alias <- function(default_name, family) { if (!all(names(family) %in% r_font_faces)) { stop("Faces must contain only: `plain`, `bold`, `italic`, `bolditalic`, `symbol`", - call. = FALSE) + call. = FALSE + ) } is_alias_object <- vapply_lgl(family, is_user_alias) @@ -76,7 +79,8 @@ validate_user_alias <- function(default_name, family) { is_valid_alias <- is_alias_object | is_alias_plain if (any(!is_valid_alias)) { - stop(call. = FALSE, + stop( + call. = FALSE, "The following faces are invalid for `", default_name, "`: ", paste0(names(family)[!is_valid_alias], collapse = ", ") ) @@ -93,7 +97,8 @@ validate_user_alias <- function(default_name, family) { file_exists <- vapply_lgl(files, file.exists) if (any(!file_exists)) { missing <- unlist(files)[!file_exists] - stop(call. = FALSE, + stop( + call. = FALSE, "Could not find font file: ", paste0(missing, collapse = ", ") ) @@ -186,7 +191,9 @@ print.font_face <- function(x, ...) { is_font_face <- function(x) inherits(x, "font_face") validate_web_fonts <- function(x) { - if (length(x) == 0) return("") + if (length(x) == 0) { + return("") + } paste0(paste( ifelse(vapply(x, is_font_face, logical(1)), x, paste0(' @import url("', x, '");')), collapse = "\n" diff --git a/R/svglite-package.R b/R/svglite-package.R new file mode 100644 index 0000000..a65cf64 --- /dev/null +++ b/R/svglite-package.R @@ -0,0 +1,6 @@ +#' @keywords internal +"_PACKAGE" + +## usethis namespace: start +## usethis namespace: end +NULL diff --git a/R/utils.R b/R/utils.R index 71860f7..5e3f746 100644 --- a/R/utils.R +++ b/R/utils.R @@ -85,20 +85,20 @@ open_manual_tests <- function() { } invalid_filename <- function(filename) { - - if (!is.character(filename) || length(filename) != 1) + if (!is.character(filename) || length(filename) != 1) { return(TRUE) + } # strip double occurences of % stripped_file <- gsub("%{2}", "", filename) # filename is fine if there are no % left - if (!grepl("%", stripped_file)) + if (!grepl("%", stripped_file)) { return(FALSE) + } # remove first allowed pattern, % followed by digits followed by [diouxX] stripped_file <- sub("%[#0 ,+-]*[0-9.]*[diouxX]", "", stripped_file) # matching leftover % indicates multiple patterns or a single incorrect pattern (e.g., %s) return(grepl("%", stripped_file)) - } #' Convert an svg file to svgz, overwriting the old file #' @param file the path to the file to convert diff --git a/README.Rmd b/README.Rmd index 13e3256..8aaeb62 100644 --- a/README.Rmd +++ b/README.Rmd @@ -17,19 +17,20 @@ knitr::opts_chunk$set( -[![R-CMD-check](https://github.com/r-lib/svglite/workflows/R-CMD-check/badge.svg)](https://github.com/r-lib/svglite/actions) [![Codecov test coverage](https://codecov.io/gh/r-lib/svglite/branch/master/graph/badge.svg)](https://app.codecov.io/gh/r-lib/svglite?branch=master) [![CRAN Status Badge](http://www.r-pkg.org/badges/version/svglite)](https://cran.r-project.org/package=svglite) - +[![R-CMD-check](https://github.com/r-lib/svglite/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/r-lib/svglite/actions/workflows/R-CMD-check.yaml) +[![Codecov test coverage](https://codecov.io/gh/r-lib/svglite/branch/main/graph/badge.svg)](https://app.codecov.io/gh/r-lib/svglite?branch=main) +[![CRAN Status Badge](http://www.r-pkg.org/badges/version/svglite)](https://cran.r-project.org/package=svglite) -svglite is a graphics device that produces clean svg output, suitable for use on the web, or hand editing. Compared to the built-in `svg()`, svglite produces smaller files, and leaves text as is, making it easier to edit the result after creation. It also support multiple nice features such as embedding of web fonts. +svglite is a graphics device that produces clean svg output, suitable for use on the web, or hand editing. Compared to the built-in `svg()`, svglite produces smaller files, and leaves text as is, making it easier to edit the result after creation. It also supports multiple nice features such as embedding of web fonts. ## Installation svglite is available on CRAN using `install.packages("svglite")`. You can install the development version from github with: ```{r, eval=FALSE} -# install.packages("devtools") -devtools::install_github("r-lib/svglite") +# install.packages("pak") +pak::pak("r-lib/svglite") ``` ## Motivation diff --git a/README.md b/README.md index d1070d5..e251584 100644 --- a/README.md +++ b/README.md @@ -5,18 +5,17 @@ -[![R-CMD-check](https://github.com/r-lib/svglite/workflows/R-CMD-check/badge.svg)](https://github.com/r-lib/svglite/actions) +[![R-CMD-check](https://github.com/r-lib/svglite/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/r-lib/svglite/actions/workflows/R-CMD-check.yaml) [![Codecov test -coverage](https://codecov.io/gh/r-lib/svglite/branch/master/graph/badge.svg)](https://app.codecov.io/gh/r-lib/svglite?branch=master) +coverage](https://codecov.io/gh/r-lib/svglite/branch/main/graph/badge.svg)](https://app.codecov.io/gh/r-lib/svglite?branch=main) [![CRAN Status Badge](http://www.r-pkg.org/badges/version/svglite)](https://cran.r-project.org/package=svglite) - svglite is a graphics device that produces clean svg output, suitable for use on the web, or hand editing. Compared to the built-in `svg()`, svglite produces smaller files, and leaves text as is, making it easier -to edit the result after creation. It also support multiple nice +to edit the result after creation. It also supports multiple nice features such as embedding of web fonts. ## Installation @@ -25,8 +24,8 @@ svglite is available on CRAN using `install.packages("svglite")`. You can install the development version from github with: ``` r -# install.packages("devtools") -devtools::install_github("r-lib/svglite") +# install.packages("pak") +pak::pak("r-lib/svglite") ``` ## Motivation @@ -59,12 +58,12 @@ svg_test <- function() { dev.off() } -bench::mark(svglite_test(), svg_test(), min_iterations = 250) -#> # A tibble: 2 x 6 +bench::mark(svglite_test(), svg_test(), min_iterations = 250, check = FALSE) +#> # A tibble: 2 × 6 #> expression min median `itr/sec` mem_alloc `gc/sec` #> -#> 1 svglite_test() 3.31ms 3.87ms 247. 561KB 5.05 -#> 2 svg_test() 10.57ms 12.19ms 76.3 177KB 1.24 +#> 1 svglite_test() 2.08ms 2.23ms 438. 691KB 7.13 +#> 2 svg_test() 6.07ms 6.26ms 159. 179KB 0.638 ``` ### File size @@ -75,7 +74,7 @@ size. `svglite()` produces much smaller files ``` r # svglite fs::file_size(tmp1) -#> 74.9K +#> 75K # svg fs::file_size(tmp2) @@ -94,7 +93,7 @@ invisible(dev.off()) # svglite - svgz fs::file_size(tmp3) -#> 9.38K +#> 9.42K ``` ### Editability diff --git a/tests/testthat.R b/tests/testthat.R index 24ca5c6..446c6ba 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -1,3 +1,11 @@ +# This file is part of the standard setup for testthat. +# It is recommended that you do not modify it. +# +# Where should you do additional test configuration? +# Learn more about the roles of various files in: +# * https://r-pkgs.org/tests.html +# * https://testthat.r-lib.org/reference/test_package.html#special-files + library(testthat) library(svglite) diff --git a/tests/testthat/test-clip.R b/tests/testthat/test-clip.R index 43f3e27..a75bd16 100644 --- a/tests/testthat/test-clip.R +++ b/tests/testthat/test-clip.R @@ -1,5 +1,3 @@ -context("Clipping") - test_that("regression test for no clipping", { svglite("test-no-clip.svg", 4, 4, user_fonts = bitstream) on.exit(dev.off()) diff --git a/tests/testthat/test-colour.R b/tests/testthat/test-colour.R index 356795b..2667402 100644 --- a/tests/testthat/test-colour.R +++ b/tests/testthat/test-colour.R @@ -1,4 +1,3 @@ -context("colour") library(xml2) test_that("transparent blacks are written", { diff --git a/tests/testthat/test-devSVG.R b/tests/testthat/test-devSVG.R index 774eafd..1afd687 100644 --- a/tests/testthat/test-devSVG.R +++ b/tests/testthat/test-devSVG.R @@ -1,11 +1,11 @@ -context("devSVG") library(xml2) style_attr <- function(nodes, attr) { style <- xml_attr(nodes, "style") ifelse(grepl(sprintf("%s: [^;]*;", attr), style), - gsub(sprintf(".*%s: ([^;]*);.*", attr), "\\1", style), - NA_character_) + gsub(sprintf(".*%s: ([^;]*);.*", attr), "\\1", style), + NA_character_ + ) } test_that("adds default background", { @@ -37,7 +37,6 @@ test_that("if bg is transparent in par(), use device driver background", { }) test_that("creating multiple pages is identical to creating multiple individual svgs", { - set.seed(42) df <- data.frame(x = rnorm(20), y = rnorm(20)) plot_one <- function() plot(df$x, df$y) @@ -85,10 +84,9 @@ test_that("creating multiple pages is identical to creating multiple individual expect_identical(readLines(f_multiple_1), readLines(f_single_1), label = "svglite first plot") expect_identical(readLines(f_multiple_2), readLines(f_single_2), label = "svglite second plot") - }) -test_that("ensure text leading white space will be rendered" , { +test_that("ensure text leading white space will be rendered", { x <- xmlSVG(plot.new()) expect_true( grepl( @@ -98,4 +96,3 @@ test_that("ensure text leading white space will be rendered" , { ) expect_equal(style_attr(xml_find_first(x, ".//rect"), "fill"), "#FFFFFF") }) - diff --git a/tests/testthat/test-lines.R b/tests/testthat/test-lines.R index d3c34e4..b42369b 100644 --- a/tests/testthat/test-lines.R +++ b/tests/testthat/test-lines.R @@ -1,4 +1,3 @@ -context("Lines") library(xml2) test_that("segments don't have fill", { diff --git a/tests/testthat/test-output.R b/tests/testthat/test-output.R index 4e7fa6b..ba8f90f 100644 --- a/tests/testthat/test-output.R +++ b/tests/testthat/test-output.R @@ -1,5 +1,3 @@ -context("Output") - test_that("different string and file output produce identical svg", { ## 1. Write to a file f1 <- tempfile() diff --git a/tests/testthat/test-path.R b/tests/testthat/test-path.R index 698c2a5..f43ccc5 100644 --- a/tests/testthat/test-path.R +++ b/tests/testthat/test-path.R @@ -1,13 +1,13 @@ -context("Paths") library(xml2) test_that("paths with winding fill mode", { x <- xmlSVG({ plot.new() polypath(c(.1, .1, .9, .9, NA, .2, .2, .8, .8), - c(.1, .9, .9, .1, NA, .2, .8, .8, .2), - col = rgb(0.5, 0.5, 0.5, 0.3), border = rgb(1, 0, 0, 0.3), - rule = "winding") + c(.1, .9, .9, .1, NA, .2, .8, .8, .2), + col = rgb(0.5, 0.5, 0.5, 0.3), border = rgb(1, 0, 0, 0.3), + rule = "winding" + ) }) path <- xml_find_first(x, ".//path") expect_equal(style_attr(path, "fill-rule"), "nonzero") @@ -21,9 +21,10 @@ test_that("paths with evenodd fill mode", { x <- xmlSVG({ plot.new() polypath(c(.1, .1, .9, .9, NA, .2, .2, .8, .8), - c(.1, .9, .9, .1, NA, .2, .8, .8, .2), - col = rgb(0.5, 0.5, 0.5, 0.3), border = rgb(1, 0, 0, 0.3), - rule = "evenodd") + c(.1, .9, .9, .1, NA, .2, .8, .8, .2), + col = rgb(0.5, 0.5, 0.5, 0.3), border = rgb(1, 0, 0, 0.3), + rule = "evenodd" + ) }) path <- xml_find_first(x, ".//path") expect_equal(style_attr(path, "fill-rule"), "evenodd") @@ -37,9 +38,10 @@ test_that("paths with no filling color", { x <- xmlSVG({ plot.new() polypath(c(.1, .1, .9, .9, NA, .2, .2, .8, .8), - c(.1, .9, .9, .1, NA, .2, .8, .8, .2), - col = NA, border = rgb(1, 0, 0, 0.3), - rule = "winding") + c(.1, .9, .9, .1, NA, .2, .8, .8, .2), + col = NA, border = rgb(1, 0, 0, 0.3), + rule = "winding" + ) }) style <- xml_text(xml_find_first(x, "//style")) expect_match(style, "fill: none;") diff --git a/tests/testthat/test-points.R b/tests/testthat/test-points.R index 04b0760..0510fe4 100644 --- a/tests/testthat/test-points.R +++ b/tests/testthat/test-points.R @@ -1,4 +1,3 @@ -context("Points") library(xml2) test_that("radius is not given in points", { @@ -44,4 +43,3 @@ test_that("points are given stroke and fill", { circle <- xml_find_all(x, ".//circle") expect_equal(style_attr(circle, "fill"), NA_character_) }) - diff --git a/tests/testthat/test-raster.R b/tests/testthat/test-raster.R index 4f0445a..10da8c2 100644 --- a/tests/testthat/test-raster.R +++ b/tests/testthat/test-raster.R @@ -1,4 +1,3 @@ -context("Raster") library(xml2) test_that("raster exists", { diff --git a/tests/testthat/test-rect.R b/tests/testthat/test-rect.R index 92fca4a..54c172b 100644 --- a/tests/testthat/test-rect.R +++ b/tests/testthat/test-rect.R @@ -1,4 +1,3 @@ -context("Rect") library(xml2) test_that("rects equivalent regardless of direction", { diff --git a/tests/testthat/test-scale.R b/tests/testthat/test-scale.R index 23f3ad0..7e2dabe 100644 --- a/tests/testthat/test-scale.R +++ b/tests/testthat/test-scale.R @@ -1,4 +1,3 @@ -context("Scale") library("grid") # Tests requiring manual oversight are registered as such. They @@ -13,13 +12,17 @@ test_that("text has correct dimensions", { w <- systemfonts::string_width("foobar", path = ttf, index = 0L, res = 1e4) * 72 / 1e4 h <- max(vapply(systemfonts::glyph_info("foobar", path = ttf, index = 0L, res = 1e4)$bbox, `[[`, numeric(1), "ymax")) * 72 / 1e4 - svglite("test-scale-text.svg", width = w / 72, height = h / 72, - user_fonts = fontquiver::font_families("Liberation")) + svglite("test-scale-text.svg", + width = w / 72, height = h / 72, + user_fonts = fontquiver::font_families("Liberation") + ) on.exit(dev.off()) grid.newpage() - grid.rect(0, 1, width = unit(w, "bigpts"), height = unit(h, "bigpts"), - hjust = 0, vjust = 1, gp = gpar(col = "red", lwd = 1)) + grid.rect(0, 1, + width = unit(w, "bigpts"), height = unit(h, "bigpts"), + hjust = 0, vjust = 1, gp = gpar(col = "red", lwd = 1) + ) grid.text("foobar", 0, 1, hjust = 0, vjust = 1, gp = gpar(fontsize = 12)) pushViewport(viewport()) }) diff --git a/tests/testthat/test-text-fonts.R b/tests/testthat/test-text-fonts.R index 716e733..35259dc 100644 --- a/tests/testthat/test-text-fonts.R +++ b/tests/testthat/test-text-fonts.R @@ -1,6 +1,3 @@ - -context("Fonts") - test_that("font sets weight/style", { x <- xmlSVG({ plot.new() @@ -29,7 +26,7 @@ test_that("symbol font family is 'Symbol'", { matched_symbol_font <- paste0('"', match_family(symbol_font), '"') x <- xmlSVG({ - plot(c(0,2), c(0,2), type = "n", axes = FALSE, xlab = "", ylab = "") + plot(c(0, 2), c(0, 2), type = "n", axes = FALSE, xlab = "", ylab = "") text(1, 1, expression(symbol("\042"))) }) text <- xml_find_all(x, ".//text") @@ -51,7 +48,8 @@ test_that("fonts are aliased", { text(0.5, 0.1, "a", family = "serif") text(0.5, 0.5, "a", family = "sans") text(0.5, 0.9, "a", family = "mono") - }) + } + ) text <- xml_find_all(x, ".//text") families <- style_attr(text, "font-family") diff --git a/tests/testthat/test-text.R b/tests/testthat/test-text.R index 0e10026..1cedb07 100644 --- a/tests/testthat/test-text.R +++ b/tests/testthat/test-text.R @@ -1,4 +1,3 @@ -context("Text") library(xml2) test_that("par(cex) affects strwidth", { @@ -8,7 +7,7 @@ test_that("par(cex) affects strwidth", { par(cex = 4) w4 <- strwidth("X") }) - expect_equal(w4 / w1, 4, tol = 1e-3) + expect_equal(w4 / w1, 4, tolerance = 1e-3) }) test_that("cex affects strwidth", { @@ -17,7 +16,7 @@ test_that("cex affects strwidth", { w1 <- strwidth("X") w4 <- strwidth("X", cex = 4) }) - expect_equal(w4 / w1, 4, tol = 1e-3) + expect_equal(w4 / w1, 4, tolerance = 1e-3) }) test_that("special characters are escaped", {