diff --git a/.Rbuildignore b/.Rbuildignore index 3043632..74b0c8d 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -3,3 +3,6 @@ ^README\.Rmd$ ^doc$ ^Meta$ +^LICENSE\.md$ +^\.github$ +^codecov\.yml$ diff --git a/.github/.gitignore b/.github/.gitignore new file mode 100644 index 0000000..2d19fc7 --- /dev/null +++ b/.github/.gitignore @@ -0,0 +1 @@ +*.html diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml new file mode 100644 index 0000000..a3ac618 --- /dev/null +++ b/.github/workflows/R-CMD-check.yaml @@ -0,0 +1,49 @@ +# 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 + +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@v3 + + - 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 diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml new file mode 100644 index 0000000..13955f1 --- /dev/null +++ b/.github/workflows/test-coverage.yaml @@ -0,0 +1,55 @@ +# 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 + +jobs: + test-coverage: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + + steps: + - uses: actions/checkout@v3 + + - 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 + needs: coverage + + - name: Test coverage + 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 + + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v3 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/DESCRIPTION b/DESCRIPTION index 67a5e01..f238155 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,11 +2,14 @@ Package: rmot Title: What the Package Does (One Line, Title Case) Version: 0.0.0.9000 Authors@R: - person("First", "Last", , "first.last@example.com", role = c("aut", "cre"), - comment = c(ORCID = "YOUR-ORCID-ID")) + c( + person(given = "Daniel", family = "Falster", role = c("aut", "ctb"), email = "daniel.falster@unsw.edu.au", comment = c(ORCID = "0000-0002-9814-092X")), + person(given = "Tess", family = "O'Brien", role = c("aut", "cre", "cph"), email = "theresa.obrien@unsw.edu.au", comment = c(ORCID = "XXXX-XXXX-XXXX-XXXX")), + person(given = "Fonti", family = "Kar", role = c("ctb"), email = "f.kar@unsw.edu.au", comment = c(ORCID = "0000-0002-2760-3974")), + person(given = "David", family= "Warton", role = c("aut", "ctb"), email = "david.warton@unsw.edu.au", comment = c(ORCID = "0000-0002-1642-628X")) + ) Description: What the package does (one paragraph). -License: `use_mit_license()`, `use_gpl3_license()` or friends to pick a - license +License: MIT + file LICENSE Encoding: UTF-8 Roxygen: list(markdown = TRUE) RoxygenNote: 7.2.3 @@ -32,5 +35,7 @@ LinkingTo: SystemRequirements: GNU make Suggests: knitr, - rmarkdown + rmarkdown, + testthat (>= 3.0.0) VignetteBuilder: knitr +Config/testthat/edition: 3 diff --git a/LICENSE b/LICENSE index bbe945a..372a7ca 100644 --- a/LICENSE +++ b/LICENSE @@ -1,21 +1,2 @@ -MIT License - -Copyright (c) 2023 Trait Ecology and Evolution - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +YEAR: 2023 +COPYRIGHT HOLDER: rmot authors diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..7f97ef8 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +# MIT License + +Copyright (c) 2023 rmot authors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/R/rmot_assign_data.R b/R/rmot_assign_data.R index 80b7028..9e62408 100644 --- a/R/rmot_assign_data.R +++ b/R/rmot_assign_data.R @@ -7,7 +7,7 @@ #' @export #' #' @examples -#' rmot_assign_data(X = Loblolly$age, Y = Loblolly$height) +#' rmot_model("linear") |> rmot_assign_data(X = Loblolly$age, Y = Loblolly$height) rmot_assign_data <- function(model_template, ...){ # Grab user expressions user_code <- rlang::enexprs(..., .check_assign = TRUE) diff --git a/R/rmot_run.R b/R/rmot_run.R index c1575bf..2e0cfa1 100644 --- a/R/rmot_run.R +++ b/R/rmot_run.R @@ -9,9 +9,9 @@ #' @examples #' rmot_model("linear") |> #' rmot_assign_data(X = Loblolly$age, -#' Y = Loblolly$height, -#' N = nrow(Loblolly)) |> -#' rmot_run() +#' Y = Loblolly$height, +#' N = nrow(Loblolly)) |> +#' rmot_run() rmot_run <- function(model_template, ...) { # Detect model diff --git a/README.Rmd b/README.Rmd index 5d1e650..bf8acb6 100644 --- a/README.Rmd +++ b/README.Rmd @@ -17,20 +17,23 @@ knitr::opts_chunk$set( # rmot +[![R-CMD-check](https://github.com/traitecoevo/rmot/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/traitecoevo/rmot/actions/workflows/R-CMD-check.yaml) +[![Codecov test coverage](https://codecov.io/gh/traitecoevo/rmot/branch/master/graph/badge.svg)](https://app.codecov.io/gh/traitecoevo/rmot?branch=master) +[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental) The goal of 'rmot' is to ... ## Installation -You can install the development version of 'rmot' from [GitHub](https://github.com/) with: +'rmot' is under active development. You can install the current developmental version of 'rmot' from [GitHub](https://github.com/) with: ``` r # install.packages("remotes") remotes::install_github("traitecoevo/rmot") ``` -## Demo +## Quick demo ```{r example} rmot_model("linear") |> @@ -42,4 +45,4 @@ rmot_model("linear") |> ## Found a bug? -Please lodge a GitHub Issue with details of the bug +Please submit a [GitHub issue](https://github.com/traitecoevo/rmot/issues) with details of the bug. A [reprex](https://reprex.tidyverse.org/) would be particularly helpful with the bug-proofing process! diff --git a/README.md b/README.md index be45a3b..dee9294 100644 --- a/README.md +++ b/README.md @@ -4,21 +4,27 @@ # rmot + +[![R-CMD-check](https://github.com/traitecoevo/rmot/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/traitecoevo/rmot/actions/workflows/R-CMD-check.yaml) +[![Codecov test +coverage](https://codecov.io/gh/traitecoevo/rmot/branch/master/graph/badge.svg)](https://app.codecov.io/gh/traitecoevo/rmot?branch=master) +[![Lifecycle: +experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental) The goal of ‘rmot’ is to … ## Installation -You can install the development version of ‘rmot’ from -[GitHub](https://github.com/) with: +‘rmot’ is under active development. You can install the current +developmental version of ‘rmot’ from [GitHub](https://github.com/) with: ``` r # install.packages("remotes") remotes::install_github("traitecoevo/rmot") ``` -## Demo +## Quick demo ``` r rmot_model("linear") |> @@ -30,4 +36,7 @@ rmot_model("linear") |> ## Found a bug? -Please lodge a GitHub Issue with details of the bug +Please submit a [GitHub +issue](https://github.com/traitecoevo/rmot/issues) with details of the +bug. A [reprex](https://reprex.tidyverse.org/) would be particularly +helpful with the bug-proofing process! diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..04c5585 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,14 @@ +comment: false + +coverage: + status: + project: + default: + target: auto + threshold: 1% + informational: true + patch: + default: + target: auto + threshold: 1% + informational: true diff --git a/man/rmot_assign_data.Rd b/man/rmot_assign_data.Rd index 23857f6..5d0a72d 100644 --- a/man/rmot_assign_data.Rd +++ b/man/rmot_assign_data.Rd @@ -18,5 +18,5 @@ updated named list with your data assigned to Stan model parameters Assign data to template } \examples{ -rmot_assign_data(X = Loblolly$age, Y = Loblolly$height) +rmot_model("linear") |> rmot_assign_data(X = Loblolly$age, Y = Loblolly$height) } diff --git a/man/rmot_run.Rd b/man/rmot_run.Rd index fb10e98..698ef55 100644 --- a/man/rmot_run.Rd +++ b/man/rmot_run.Rd @@ -20,7 +20,7 @@ Run a linear model in Stan \examples{ rmot_model("linear") |> rmot_assign_data(X = Loblolly$age, - Y = Loblolly$height, - N = nrow(Loblolly)) |> - rmot_run() + Y = Loblolly$height, + N = nrow(Loblolly)) |> + rmot_run() } diff --git a/tests/testthat.R b/tests/testthat.R new file mode 100644 index 0000000..33b5b88 --- /dev/null +++ b/tests/testthat.R @@ -0,0 +1,12 @@ +# 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/testing-design.html#sec-tests-files-overview +# * https://testthat.r-lib.org/articles/special-files.html + +library(testthat) +library(rmot) + +test_check("rmot") diff --git a/tests/testthat/test-rmot_assign_data.R b/tests/testthat/test-rmot_assign_data.R new file mode 100644 index 0000000..1d0ca7c --- /dev/null +++ b/tests/testthat/test-rmot_assign_data.R @@ -0,0 +1,17 @@ +test_that("Execution and output", { + + lm_loblloy <- rmot_model("linear") |> + rmot_assign_data(X = Loblolly$age) + + expect_named(lm_loblloy) + + expect_visible(lm_loblloy) + + expect_type(lm_loblloy, "list") + + lm_empty <- rmot_model("linear") + + expect_null(lm_empty$X) + + expect_true(length(lm_loblloy$X) > 0) +}) diff --git a/tests/testthat/test-rmot_models.R b/tests/testthat/test-rmot_models.R new file mode 100644 index 0000000..182fc5a --- /dev/null +++ b/tests/testthat/test-rmot_models.R @@ -0,0 +1,19 @@ +test_that("Execution and output", { + expect_named(rmot_model("linear")) + expect_type(rmot_model("linear"), "list") + expect_visible(rmot_model("linear")) + + expect_named(rmot_model("constant_single")) + expect_type(rmot_model("constant_single"), "list") + expect_visible(rmot_model("constant_single")) + + lm_test <- rmot_model("linear") |> + rmot_assign_data(X = Loblolly$age, + Y = Loblolly$height, + N = nrow(Loblolly)) |> + rmot_run(chains = 2, iter = 300, verbose = FALSE, show_messages = FALSE) + + expect_visible(lm_test) + + expect_s4_class(lm_test, "stanfit") +})