diff --git a/.Rbuildignore b/.Rbuildignore index 5ca465b..95b3786 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -2,3 +2,7 @@ ^\.Rproj\.user$ ^data-raw$ ^\.devcontainer$ +^\.github$ +^_pkgdown\.yml$ +^docs$ +^pkgdown$ diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index aa53181..d2886ca 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -13,7 +13,7 @@ "packages": "clang,clang-format,clang-tidy,cmake,doxygen,g++,gcc,libxt6,libxtst6,make,ninja-build" }, "ghcr.io/rocker-org/devcontainer-features/r-packages:1": { - "packages": "dplyr,devtools,ggplot2,jsonlite,methods,mockery,Rcpp,RcppEigen,scales,snowfall,TMB,tibble,tidyr,usethis", + "packages": "dplyr,devtools,ggplot2,jsonlite,methods,mockery,Rcpp,RcppEigen,scales,snowfall,spelling,TMB,tibble,tidyr,usethis", "installSystemRequirements": true }, // option to run rstudio. you can type rserver into the command line to 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/call-allcontributors.yml b/.github/workflows/call-allcontributors.yml new file mode 100644 index 0000000..c7183b6 --- /dev/null +++ b/.github/workflows/call-allcontributors.yml @@ -0,0 +1,41 @@ +# Runs allcontributors::add_contributors() to add, or update, an alphabetized +# list of contributors to the README.md file and open a new PR with those +# changes. +name: Collect contributors + +on: + push: + workflow_dispatch: + +jobs: + run-r-script: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + permissions: + contents: write + pull-requests: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Setup R + uses: r-lib/actions/setup-r@v2 + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + packages: | + gh + allcontributors + - name: Collect contributor data + run: Rscript -e 'allcontributors::add_contributors(files = c("README.md"))' + - name: Create Pull Request + uses: peter-evans/create-pull-request@v7 + with: + commit-message: "chore: Updates contributors" + branch: update-contributors + base: main + title: "Update contributors" + body: "This PR updates the contributors list." + labels: "auto-update" + add-paths: | + README.md \ No newline at end of file diff --git a/.github/workflows/call-build-pkgdown.yml b/.github/workflows/call-build-pkgdown.yml new file mode 100644 index 0000000..b3dc470 --- /dev/null +++ b/.github/workflows/call-build-pkgdown.yml @@ -0,0 +1,14 @@ +# Checks that the pkgdown site builds for a repository, assuming that one +# already exists, but it does not actually deploy it. See +# call-update-pkgdown.yml for that. +name: call-build-pkgdown + +on: + pull_request: + branches: + - main + workflow_dispatch: + +jobs: + call-workflow: + uses: nmfs-ost/ghactions4r/.github/workflows/build-pkgdown.yml@main \ No newline at end of file diff --git a/.github/workflows/call-doc-and-style-r.yml b/.github/workflows/call-doc-and-style-r.yml new file mode 100644 index 0000000..15d7db7 --- /dev/null +++ b/.github/workflows/call-doc-and-style-r.yml @@ -0,0 +1,16 @@ +# Runs devtools::document() and styler::style_active_package(), then opens a +# pull request to the branch that had changes in the push that triggered the +# workflow. +name: call-doc-and-style-r + +on: + push: + branches: + - main + workflow_dispatch: + +jobs: + call-workflow: + uses: nmfs-ost/ghactions4r/.github/workflows/doc-and-style-r.yml@main + secrets: + PAT: ${{ secrets.PAT }} \ No newline at end of file diff --git a/.github/workflows/call-pr-checklist.yml b/.github/workflows/call-pr-checklist.yml new file mode 100644 index 0000000..e9f558a --- /dev/null +++ b/.github/workflows/call-pr-checklist.yml @@ -0,0 +1,42 @@ +# Adds a comment to a newly opened PR letting reviewers know what should be +# included in their review. +name: Add a comment with reviewer checklist when PR opened + +on: + pull_request: + types: [opened] + +jobs: + pr-checklist: + runs-on: ubuntu-latest + name: pr-checklist + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: 'Comment PR' + uses: actions/github-script@v0.3.0 + if: github.event_name == 'pull_request' + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + var msg = `# Instructions for code reviewer + + Hello reviewer, thanks for taking the time to review this PR! + + - Please use this checklist during your review, checking off items that you have verified are complete, but feel free to skip over items that are not relevant! + - See the [GitHub documentation for how to comment on a PR](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/commenting-on-a-pull-request) to indicate where you have questions or changes are needed before approving the PR. + - Please use conventions in the [guidelines for conventional commit messages](https://www.conventionalcommits.org/) for both commit messages and comments. + - PR reviews are a great way to learn so feel free to share your tips and tricks. However, when suggesting changes to the PR that are optional please include \`nit:\` (for nitpicking) as the comment type. For example, \`nit:\` I prefer using a \`data.frame()\` instead of a \`matrix\` because ... + - Engage with the developer when they respond to comments and check off additional boxes as they become complete so the PR can be merged in when all the tasks are fulfilled. Make it clear when the PR is approved by selecting the approved status, and potentially by commenting on the PR with something like \`This PR is now ready to be merged, no additional changes are needed\`. + + ## Checklist + + - [ ] The PR is requested to be merged into the appropriate branch (typically dev). + - [ ] The code is well-designed. + - [ ] The functionality is good for the users of the code. + - [ ] Code coverage remains high, indicating the new code is tested. + - [ ] The code is commented and the comments are clear, useful, and mostly explain why instead of what. + - [ ] Code is appropriately documented. + ` + const { issue: { number: issue_number }, repo: { owner, repo } } = context; + github.issues.createComment({ issue_number, owner, repo, body: msg }); \ No newline at end of file diff --git a/.github/workflows/call-r-cmd-check.yml b/.github/workflows/call-r-cmd-check.yml new file mode 100644 index 0000000..ce9994c --- /dev/null +++ b/.github/workflows/call-r-cmd-check.yml @@ -0,0 +1,17 @@ +# Runs R CMD CHECK on the package. +name: call-r-cmd-check + +on: + push: + workflow_dispatch: + +# no permissions are needed by the default github token for this workflow to +# run, so don't pass any. +# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/controlling-permissions-for-github_token +permissions: {} + +jobs: + call-workflow: + uses: nmfs-ost/ghactions4r/.github/workflows/r-cmd-check.yml@main + with: + gha_timeout_minutes: 60 \ No newline at end of file diff --git a/.github/workflows/call-spell-check.yml b/.github/workflows/call-spell-check.yml new file mode 100644 index 0000000..f73da2e --- /dev/null +++ b/.github/workflows/call-spell-check.yml @@ -0,0 +1,15 @@ +# Runs devtools::spell_check(). +name: call-spell-check + +on: + pull_request: + branches: + - main + push: + branches: + - main + workflow_dispatch: + +jobs: + call-workflow: + uses: nmfs-ost/ghactions4r/.github/workflows/spell-check.yml@main \ No newline at end of file diff --git a/.github/workflows/call-update-data-r.yml b/.github/workflows/call-update-data-r.yml new file mode 100644 index 0000000..5f8466b --- /dev/null +++ b/.github/workflows/call-update-data-r.yml @@ -0,0 +1,17 @@ +# Update data files in /data whenever changes are made to files in /data-raw. +# This workflow automatically commits changes directly to the working branch. +name: call-update-data-r + +on: + push: + paths: + - 'data-raw/**' + workflow_dispatch: + +jobs: + call-workflow: + uses: NOAA-FIMS/ecosystemdata/.github/workflows/update-data-r.yml@add-gha-checks + secrets: + PAT: ${{ secrets.PAT }} + with: + commit-directly: true \ No newline at end of file diff --git a/.github/workflows/call-update-pkgdown.yml b/.github/workflows/call-update-pkgdown.yml new file mode 100644 index 0000000..8134a6a --- /dev/null +++ b/.github/workflows/call-update-pkgdown.yml @@ -0,0 +1,11 @@ +# Updates the exiting pkgdown site for a repository by deploying the changes +# made to the pkgdown site to a branch called gh-pages. +name: call-update-pkgdown + +on: + push: + branches: [main] + +jobs: + call-workflow: + uses: nmfs-ost/ghactions4r/.github/workflows/update-pkgdown.yml@main \ No newline at end of file diff --git a/.github/workflows/greetings.yml b/.github/workflows/greetings.yml new file mode 100644 index 0000000..24b36de --- /dev/null +++ b/.github/workflows/greetings.yml @@ -0,0 +1,26 @@ +name: Greetings + +on: [pull_request_target, issues] + +jobs: + greeting: + runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write + steps: + - uses: actions/first-interaction@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + issue-message: > + Thank you for contributing to {ecosystemdata} and opening your first issue + here! We are happy to have your contributions. We encourage you to + introduce yourself to the community on the [introduction thread in + our Discussions](https://github.com/orgs/NOAA-FIMS/discussions/801). + pr-message: > + Thank you for contributing to {ecosystemdata} and opening your first PR + here! We are happy to have your contributions. Please ensure that the + PR is made to the dev branch and let us know if you need any help! + Also, we encourage you to introduce yourself to the community on the + [introduction thread in our + Discussions](https://github.com/orgs/NOAA-FIMS/discussions/801). \ No newline at end of file diff --git a/.github/workflows/test-download-artifact.yml b/.github/workflows/test-download-artifact.yml new file mode 100644 index 0000000..f4bff6e --- /dev/null +++ b/.github/workflows/test-download-artifact.yml @@ -0,0 +1,22 @@ +name: test-download-artifact +on: + workflow_run: + workflows: ["call-r-cmd-check"] + types: + - completed + branches: + - add-gha-checks + workflow_dispatch: + +permissions: + contents: read + actions: read + +jobs: + test-simple-model: + if: ${{ github.event.workflow_run.conclusion == 'success' }} + runs-on: ubuntu-latest + + steps: + - name: Checkout test repo (this repo) + uses: actions/checkout@v4 diff --git a/.github/workflows/update-data-r.yml b/.github/workflows/update-data-r.yml new file mode 100644 index 0000000..eef64b6 --- /dev/null +++ b/.github/workflows/update-data-r.yml @@ -0,0 +1,106 @@ +# Update /data when files in /data-raw are changed +# This workflow runs R code to regenerate data in /data when files in /data-raw are changed. +# Once the update is complete, the changes are committed. +# If 'commit-directly' is set to false (the default), a pull request will be opened +# to the branch where the workflow was triggered. The PR will contain the commit with updated data. +# If 'commit-directly' is set to true, changes are pushed directly to the triggering branch. +# Note that the job will fail if force pushing is required. +on: + workflow_call: + secrets: + PAT: + required: false + inputs: + commit-directly: + required: false + type: boolean + default: false + +# Give the fewest permissions possible. content and pull-requests are necessary. +# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/controlling-permissions-for-github_token +permissions: + contents: write + pull-requests: write + +# Cancel runs happening simultaneously on the same branch. +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +name: update data + +jobs: + update-data-r: + name: update R data from /data-raw + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.PAT }} + steps: + - name: setup env using GITHUB_TOKEN, if no pat + if: env.GITHUB_PAT == '' + run: echo "GITHUB_PAT=${{ secrets.GITHUB_TOKEN}}" >> "$GITHUB_ENV" + + - name: checkout, make changes and submit as pr on new branch + if: inputs.commit-directly == false + uses: actions/checkout@v4 + + - name: checkout, make changes directly + if: inputs.commit-directly == true + uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: | + devtools + + - name: Run R code to update files in /data + run: | + devtools::install() + r_scripts <- list.files("data-raw", pattern = "\\.R$", full.names = TRUE) + if (length(r_scripts) > 0) { + for (script in r_scripts) { + system(paste("Rscript ", shQuote(script))) + } + } else { + message("No R scripts found in /data-raw.") + } + shell: Rscript {0} + + - name: commit if using commit directly + if: inputs.commit-directly == true + uses: stefanzweifel/git-auto-commit-action@v6 + with: + commit_message: 'update data from /data-raw' + + - name: specify base branch + id: specify-base + if: ${{ inputs.commit-directly == false }} + run: | + if [ -n ${{ github.head_ref }} ]; then + echo "base=${{github.head_ref}}" >> "$GITHUB_OUTPUT" + elif [ -n ${{ github.ref_name }} ]; then + echo "base=${{github.ref_name}}" >> "$GITHUB_OUTPUT" + else + echo "both github.head_ref and github.ref_name do not exist" >&2 + exit 1 + fi + + - name: Create Pull Request + if: ${{inputs.commit-directly == false}} + uses: peter-evans/create-pull-request@v7 + with: + commit-message: 'update R data from /data-raw' + token: ${{ env.GITHUB_PAT }} + branch: update-data-${{ github.ref_name }} + base: ${{ steps.specify-base.outputs.base }} + title: 'update R data' + body: | + Auto-generated by [update-data-r.yml][1] + + [1]: https://github.com/NOAA-FIMS/ecosystemdata/tree/main/.github/workflows/update-data-r.yml diff --git a/.gitignore b/.gitignore index 7cc8b6a..b27cb91 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,4 @@ po/*~ # RStudio Connect folder rsconnect/ .Rproj.user +docs diff --git a/DESCRIPTION b/DESCRIPTION index 0790c43..e7c0ff7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -31,3 +31,4 @@ Config/testthat/edition: 3 Depends: R (>= 3.5) LazyData: true +Language: en-US diff --git a/R/get_functional_groups.R b/R/get_functional_groups.R index c289961..20fe9b1 100644 --- a/R/get_functional_groups.R +++ b/R/get_functional_groups.R @@ -4,7 +4,7 @@ utils::globalVariables(c("V1", "V2")) #' #' @description #' Functional group names are useful for the column names of output data from -#' an EeW model, and thus, this function is a way to get them automatically +#' an EwE model, and thus, this function is a way to get them automatically #' from the EwE output. The functional group names come from the basic #' estimates file. #' diff --git a/R/load_.R b/R/load_.R index cd97355..32204cc 100644 --- a/R/load_.R +++ b/R/load_.R @@ -7,7 +7,7 @@ utils::globalVariables(c("timestep", "group", "fleet", "month", "type", "year")) #' #' @param file_path The path to the CSV file containing the EwE output data. #' @param model_years A vector of years corresponding to the model years. TODO: this can be removed -#' after havgina a utility function to extract model years globally from annual data +#' after having a utility function to extract model years globally from annual data #' @param functional_groups A vector of names of the functional groups in the model. #' #' @export @@ -28,7 +28,7 @@ utils::globalVariables(c("timestep", "group", "fleet", "month", "type", "year")) #' ) #' } # TODO: double check that average of monthly data matches annual data for more than just biomass -load_csv_ewe <- function(file_path, model_years, functional_groups) { +load_csv_ewe <- function(files_path, model_years, functional_groups) { # Load the EwE data file and extract the data data <- read_n_skip(file_path) if ( diff --git a/README.md b/README.md index 17df434..7d61547 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,35 @@ # ecosystemdata Ecosystem operating model output data. + +## Contributors + + + + + + +All contributions to this project are gratefully acknowledged using the [`allcontributors` package](https://github.com/ropensci/allcontributors) following the [all-contributors](https://allcontributors.org) specification. Contributions of any kind are welcome! + +
|
+
+ +Bai-Li-NOAA + |
+
+
+ +kellijohnson-NOAA + |
+