Skip to content

Commit

Permalink
added print.maze as per issue #3. updated GHA workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
kstreet13 committed May 9, 2024
1 parent faf0615 commit 40e3f7d
Show file tree
Hide file tree
Showing 10 changed files with 184 additions and 72 deletions.
4 changes: 3 additions & 1 deletion .Rproj.user/shared/notebooks/paths
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/Users/kstreet/Projects/mazing/vignettes/inspiration.Rmd="242599EE"
/Users/kellystreet/Projects/Packages/mazing/R/plotting.R="6786BE2A"
/Users/kellystreet/Projects/Packages/mazing/tests/testthat.R="D8E3519A"
/Users/kellystreet/Projects/Packages/mazing/vignettes/inspiration.Rmd="CA08C1EB"
90 changes: 23 additions & 67 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag.
# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches:
- main
- master
branches: [main, master]
pull_request:
branches:
- main
- master
branches: [main, master]

name: R-CMD-check

permissions: read-all

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}
Expand All @@ -22,75 +20,33 @@ jobs:
fail-fast: false
matrix:
config:
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: macOS-latest, r: 'release'}
- {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v1
- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- uses: r-lib/actions/setup-pandoc@v1

- name: Query dependencies
run: |
install.packages('remotes')
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
shell: Rscript {0}

- name: Restore R package cache
uses: actions/cache@v2
- uses: r-lib/actions/setup-r-dependencies@v2
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-

- name: Install system dependencies
if: runner.os == 'Linux'
run: |
while read -r cmd
do
eval sudo $cmd
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))')
extra-packages: any::rcmdcheck
needs: check

- name: Install dependencies
run: |
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("rcmdcheck")
shell: Rscript {0}

- name: Check
env:
_R_CHECK_CRAN_INCOMING_REMOTE_: false
run: |
options(crayon.enabled = TRUE)
rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check")
shell: Rscript {0}

- name: Upload check results
if: failure()
uses: actions/upload-artifact@main
- uses: r-lib/actions/check-r-package@v2
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check

- name: Install covr
if: runner.os == 'macOS'
run: |
remotes::install_cran("covr")
shell: Rscript {0}

- name: Test coverage
if: runner.os == 'macOS'
run: covr::codecov()
shell: Rscript {0}
upload-snapshots: true
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
61 changes: 61 additions & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: test-coverage

permissions: read-all

jobs:
test-coverage:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr, any::xml2
needs: coverage

- name: Test coverage
run: |
cov <- covr::package_coverage(
quiet = FALSE,
clean = FALSE,
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
)
covr::to_cobertura(cov)
shell: Rscript {0}

- uses: codecov/codecov-action@v4
with:
fail_ci_if_error: ${{ github.event_name != 'pull_request' && true || false }}
file: ./cobertura.xml
plugin: noop
disable_search: true
token: ${{ secrets.CODECOV_TOKEN }}

- 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@v4
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Imports:
methods,
stats
Suggests:
bittermelon,
rmarkdown,
emojifont,
knitr,
Expand All @@ -24,6 +25,6 @@ Suggests:
testthat (>= 3.0.0),
covr
VignetteBuilder: knitr
RoxygenNote: 7.1.1
RoxygenNote: 7.3.1
BugReports: https://github.com/kstreet13/mazing/issues
Config/testthat/edition: 3
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

S3method(lines,maze)
S3method(plot,maze)
S3method(print,maze)
export(as.maze)
export(condense_matrix)
export(expand_matrix)
Expand All @@ -15,3 +16,4 @@ importFrom(graphics,lines)
importFrom(methods,as)
importFrom(methods,is)
importFrom(stats,median)
importFrom(utils,packageVersion)
43 changes: 43 additions & 0 deletions R/maze.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#' @return For \code{is.maze} a logical value indicating if the input is a valid
#' \code{maze}.
#'
#' @seealso [print.maze()]
#'
#' @examples
#' maze(10,10)
#' @export
Expand Down Expand Up @@ -80,3 +82,44 @@ as.maze <- function(x){
}


#' @title Print Maze
#' @name print.maze
#' @description
#' Display a \code{maze} object.
#'
#' @param x A \code{maze} object.
#' @param walls logical value, indicating that the walls of the maze should be
#' plotted, rather than the paths through the maze. Default is \code{FALSE}.
#' @param start,end The coordinates of the starting and ending points of a path
#' through the maze, or descriptions of relative locations (eg.
#' \code{"topleft"}, see \code{\link{find_maze_refpoint}}). If not provided,
#' no path will be drawn.
#' @param compress How to compress the bitmap representation, see
#' \code{\link[bittermelon]{print.bm_bitmap}}. For \code{maze} objects, the
#' default is \code{"v"} for vertical.
#' @param ... Further arguments passed to
#' \code{\link[bittermelon]{print.bm_bitmap}}, if the \code{bittermelon}
#' package is available.
#'
#' @details If the \code{\link[bittermelon]{bittermelon}} package is available,
#' \code{print.maze} prints a representation of the maze az a bitmap object.
#' Otherwise, it prints the matrix representation.
#'
#' @examples
#' m <- maze(10,10)
#' print(m)
#'
#' @importFrom utils packageVersion
#' @export
print.maze <- function(x, ..., walls = FALSE, start = NULL, end = NULL,
compress = "v") {
if(requireNamespace("bittermelon", quietly = TRUE) &&
packageVersion("bittermelon") >= "1.2.0-2"){
bm <- bittermelon::as_bm_bitmap(x, walls = walls, start = start, end = end)
print(bm, compress = compress, ...)
}else{
print.default(x)
}
}


4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# mazing

<!-- badges: start -->
[![R-CMD-check](https://github.com/kstreet13/mazing/workflows/R-CMD-check/badge.svg)](https://github.com/kstreet13/mazing/actions)
[![Codecov test coverage](https://codecov.io/gh/kstreet13/mazing/branch/master/graph/badge.svg)](https://codecov.io/gh/kstreet13/mazing?branch=master)
[![R-CMD-check](https://github.com/kstreet13/mazing/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/kstreet13/mazing/actions/workflows/R-CMD-check.yaml)
[![test-coverage](https://github.com/kstreet13/mazing/actions/workflows/test-coverage.yaml/badge.svg)](https://github.com/kstreet13/mazing/actions/workflows/test-coverage.yaml)
<!-- badges: end -->

<img src=inst/mazing.png height="300">
Expand Down
3 changes: 3 additions & 0 deletions man/maze.Rd

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

40 changes: 40 additions & 0 deletions man/print.maze.Rd

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

6 changes: 5 additions & 1 deletion tests/testthat/test-mazing.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,12 @@ test_that("pathfinding works as expected", {
expect_true(all(p[,2] == 1))
})

test_that("plotting functions do not give errors", {
test_that("plotting and printing functions do not give errors", {
m <- maze(10, 10)

expect_invisible(print(m))
# can't find a way to test this and the matrix print method

expect_invisible(plot(m))
expect_invisible(plot(m, walls = TRUE))
expect_invisible(plot(m, adjust = c(.5,.5)))
Expand Down

0 comments on commit 40e3f7d

Please sign in to comment.