Skip to content

Commit

Permalink
add test for codetools
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinushey committed Aug 20, 2024
1 parent 2cc063b commit 0c82dbf
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 13 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
^.*\.Rproj$
^\.Rproj\.user$
^README\.Rmd$
^\.github$
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
52 changes: 52 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# 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: R-CMD-check.yaml

permissions: read-all

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v4

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

- 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-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
4 changes: 4 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ title: dotty
output: github_document
---

<!-- badges: start -->
[![R-CMD-check](https://github.com/kevinushey/dotty/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/kevinushey/dotty/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->

Destructuring assignments in R with the `.` object.


Expand Down
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
dotty
================

<!-- badges: start -->

[![R-CMD-check](https://github.com/kevinushey/dotty/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/kevinushey/dotty/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->

Destructuring assignments in R with the `.` object.

### Usage
Expand Down Expand Up @@ -45,24 +50,19 @@ c(x, y, z)
c(major, minor, patch)
```

## [1] 4 2 2

``` r
# compute on values in object -- this is probably too magical
.[total = sum(a)] <- list(a = 1:5)
total
```

## [1] 15
## [1] 4 4 1

### R CMD check

If you’d like to use `dotty` in your CRAN package, you can avoid
`R CMD check` warnings by including a file called `R/zzz.R` with the
contents:

dotty::dotify()
.onLoad <- function(libname, pkgname) {
dotty::dotify()
}

This function will search for usages of `dotty`, and call
`utils::globalVariables()` to assert to `R CMD check` that such
variables are valid for use.
This function patches
[codetools](https://cran.r-project.org/package=codetools) so that
variables usages in `.` expressions can be linted as though those were
regular bindings / assignments.
20 changes: 20 additions & 0 deletions tests/testthat/test-dot.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,23 @@ test_that("we can destructure R versions", {
expect_equal(minor, unclass(version)[[1L]][[2L]])
expect_equal(patch, unclass(version)[[1L]][[3L]])
})

test_that("dotify helps codetools understand dotty usages", {

skip_if_not_installed("codetools")

example <- function() {
.[apple, banana] <- c(1, 2)
c(apple, banana, cherry)
}

messages <- ""
result <- codetools::checkUsage(example, report = function(x) {
messages <<- paste(messages, x, sep = "")
})

expect_false(grepl("apple", messages))
expect_false(grepl("banana", messages))
expect_true(grepl("cherry", messages))

})

0 comments on commit 0c82dbf

Please sign in to comment.