diff --git a/.Rbuildignore b/.Rbuildignore index 2eb1576f..4dcee218 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,3 +1,8 @@ ^dev$ ^\.here$ ^LICENSE\.md$ +^README\.Rmd$ +^\.github$ +^_pkgdown\.yml$ +^docs$ +^pkgdown$ diff --git a/.github/.gitignore b/.github/.gitignore new file mode 100644 index 00000000..2d19fc76 --- /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 00000000..a3ac6182 --- /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/pkgdown.yaml b/.github/workflows/pkgdown.yaml new file mode 100644 index 00000000..ed7650c7 --- /dev/null +++ b/.github/workflows/pkgdown.yaml @@ -0,0 +1,48 @@ +# 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] + release: + types: [published] + workflow_dispatch: + +name: pkgdown + +jobs: + pkgdown: + runs-on: ubuntu-latest + # Only restrict concurrency for non-PR jobs + concurrency: + group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + permissions: + contents: write + steps: + - uses: actions/checkout@v3 + + - uses: r-lib/actions/setup-pandoc@v2 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::pkgdown, local::. + needs: website + + - name: Build site + run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE) + shell: Rscript {0} + + - name: Deploy to GitHub pages 🚀 + if: github.event_name != 'pull_request' + uses: JamesIves/github-pages-deploy-action@v4.4.1 + with: + clean: false + branch: gh-pages + folder: docs diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml new file mode 100644 index 00000000..2c5bb502 --- /dev/null +++ b/.github/workflows/test-coverage.yaml @@ -0,0 +1,50 @@ +# 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 diff --git a/.gitignore b/.gitignore index 507e045a..c9beb358 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ .RData .DS_Store .httr-oauth +inst/doc +docs diff --git a/DESCRIPTION b/DESCRIPTION index 0acb0dea..14e86e89 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,13 +1,27 @@ Package: rix -Version: 0.0.0.9000 Title: Rix: Reproducible Environments With Nix -Description: Provides helper functions to create reproducible development environments using the Nix package manager. -Authors@R: person(given = "Bruno", - family = "Rodrigues", - role = c("aut", "cre"), - email = "brodriguesco@protonmail.com", - comment = c(ORCID = "0000-0002-3211-3689")) +Version: 0.0.0.9000 +Authors@R: + person("Bruno", "Rodrigues", , "brodriguesco@protonmail.com", role = c("aut", "cre"), + comment = c(ORCID = "0000-0002-3211-3689")) +Description: Provides helper functions to create reproducible development + environments using the Nix package manager. License: GPL (>= 3) +Depends: + R (>= 2.10) +Imports: + magrittr +Suggests: + dplyr, + janitor, + knitr, + rmarkdown, + rvest, + testthat +VignetteBuilder: + knitr +Config/fusen/version: 0.5.1 Encoding: UTF-8 +LazyData: true Roxygen: list(markdown = TRUE) RoxygenNote: 7.2.3 diff --git a/NAMESPACE b/NAMESPACE new file mode 100644 index 00000000..64cac2aa --- /dev/null +++ b/NAMESPACE @@ -0,0 +1,5 @@ +# Generated by roxygen2: do not edit by hand + +export("%>%") +export(my_fun) +importFrom(magrittr,"%>%") diff --git a/NEWS.md b/NEWS.md new file mode 100644 index 00000000..2f98f1a1 --- /dev/null +++ b/NEWS.md @@ -0,0 +1,3 @@ +# rix (development version) + +* Initial CRAN submission. diff --git a/R/included-datasets.R b/R/included-datasets.R new file mode 100644 index 00000000..bcb68071 --- /dev/null +++ b/R/included-datasets.R @@ -0,0 +1,14 @@ +# WARNING - Generated by {fusen} from dev/data_doc.Rmd: do not edit by hand + +#' r_nix_revs +#' +#' Nix revisions with old R releases +#' +#' @format A data frame with 34 rows and 3 variables: +#' \describe{ +#' \item{ version }{ R version } +#' \item{ revision }{ Nix revision containing this version of R } +#' \item{ date }{ Date when this revision was available } +#' } +#' @source Nix Package Version, by Marcelo Lazaroni +"r_nix_revs" diff --git a/R/my_fun.R b/R/my_fun.R new file mode 100644 index 00000000..eededa75 --- /dev/null +++ b/R/my_fun.R @@ -0,0 +1,12 @@ +# WARNING - Generated by {fusen} from dev/flat_minimal_package.Rmd: do not edit by hand + +#' my_fun Title +#' +#' @return 1 +#' @export +#' +#' @examples +#' my_fun() +my_fun <- function() { + 1 +} diff --git a/R/rix-package.R b/R/rix-package.R new file mode 100644 index 00000000..a65cf643 --- /dev/null +++ b/R/rix-package.R @@ -0,0 +1,6 @@ +#' @keywords internal +"_PACKAGE" + +## usethis namespace: start +## usethis namespace: end +NULL diff --git a/R/utils-pipe.R b/R/utils-pipe.R new file mode 100644 index 00000000..fd0b1d13 --- /dev/null +++ b/R/utils-pipe.R @@ -0,0 +1,14 @@ +#' Pipe operator +#' +#' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. +#' +#' @name %>% +#' @rdname pipe +#' @keywords internal +#' @export +#' @importFrom magrittr %>% +#' @usage lhs \%>\% rhs +#' @param lhs A value or the magrittr placeholder. +#' @param rhs A function call using the magrittr semantics. +#' @return The result of calling `rhs(lhs)`. +NULL diff --git a/README.Rmd b/README.Rmd new file mode 100644 index 00000000..7ffffdd5 --- /dev/null +++ b/README.Rmd @@ -0,0 +1,56 @@ +--- +output: github_document +--- + + + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + fig.path = "man/figures/README-", + out.width = "100%" +) +``` + +# rix + + +[![R-CMD-check](https://github.com/b-rodrigues/rix/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/b-rodrigues/rix/actions/workflows/R-CMD-check.yaml) + + +The goal of rix is to ... + +## Installation + +You can install the development version of rix from [GitHub](https://github.com/) with: + +``` r +# install.packages("devtools") +devtools::install_github("b-rodrigues/rix") +``` + +## Example + +This is a basic example which shows you how to solve a common problem: + +```{r example} +library(rix) +## basic example code +``` + +What is special about using `README.Rmd` instead of just `README.md`? You can include R chunks like so: + +```{r cars} +summary(cars) +``` + +You'll still need to render `README.Rmd` regularly, to keep `README.md` up-to-date. `devtools::build_readme()` is handy for this. + +You can also embed plots, for example: + +```{r pressure, echo = FALSE} +plot(pressure) +``` + +In that case, don't forget to commit and push the resulting figure files, so they display on GitHub and CRAN. diff --git a/_pkgdown.yml b/_pkgdown.yml new file mode 100644 index 00000000..d71acfb9 --- /dev/null +++ b/_pkgdown.yml @@ -0,0 +1,4 @@ +url: ~ +template: + bootstrap: 5 + diff --git a/data/r_nix_revs.rda b/data/r_nix_revs.rda new file mode 100644 index 00000000..68b8c9c4 Binary files /dev/null and b/data/r_nix_revs.rda differ diff --git a/dev/.#0-dev_history.Rmd b/dev/.#0-dev_history.Rmd deleted file mode 120000 index 50d0c60d..00000000 --- a/dev/.#0-dev_history.Rmd +++ /dev/null @@ -1 +0,0 @@ -root@9d1fc872b90f.1 \ No newline at end of file diff --git a/dev/0-dev_history.Rmd b/dev/0-dev_history.Rmd index 209947ca..86dc6ae4 100755 --- a/dev/0-dev_history.Rmd +++ b/dev/0-dev_history.Rmd @@ -16,15 +16,16 @@ All commands that you use to use when developing packages... fusen::fill_description( pkg = here::here(), fields = list( - Title = "Build A Package From Rmarkdown File", - Description = "Use Rmarkdown First method to build your package. Start your package with documentation. Everything can be set from a Rmarkdown file in your project.", + Title = "Rix: Reproducible Environments with Nix", + Description = "Provides helper functions to create reproducible development environments using the Nix package manager.", `Authors@R` = c( - person("John", "Doe", email = "john@email.me", role = c("aut", "cre"), comment = c(ORCID = "0000-0000-0000-0000")) + person("Bruno", "Rodrigues", email = "brodriguesco@protonmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-3211-3689")) ) ) ) # Define License with use_*_license() -usethis::use_mit_license("John Doe") +usethis::use_gpl3_license() + ``` # All-in-one function to deploy publicly on GitHub @@ -34,7 +35,7 @@ See `vignette("share-on-a-github-website", package = "fusen")` for more informat ```{r, eval=FALSE} # _All-in-one share of your package and its documentation on GitHub -fusen::init_share_on_github() +#fusen::init_share_on_github() ``` @@ -43,26 +44,49 @@ fusen::init_share_on_github() ```{r, eval=FALSE} usethis::use_git() # Deal with classical files to ignore -usethis::git_vaccinate() +#usethis::git_vaccinate() # Use main for primary branch -usethis::git_default_branch_rename() +#usethis::git_default_branch_rename() ``` # Set extra sources of documentation ```{r, eval=FALSE} # Install a first time -remotes::install_local() +#remotes::install_local() # README -usethis::use_readme_rmd() +#usethis::use_readme_rmd() # Code of Conduct -usethis::use_code_of_conduct("contact@fake.com") +#usethis::use_code_of_conduct("contact@fake.com") # NEWS -usethis::use_news_md() +#usethis::use_news_md() ``` **From now, you will need to "inflate" your package at least once to be able to use the following commands. Let's go to your flat template, and come back here later if/when needed.** +```{r development-inflate, eval=FALSE} +# Run but keep eval=FALSE to avoid infinite loop +# Execute in the console directly +fusen::inflate(flat_file = "dev/save_r_nix_revs.Rmd", + vignette_name = "dev-save_r_nix_revs", + overwrite = TRUE) +``` + +```{r} +local({ + knitr::knit("vignettes/dev-save_r_nix_revs.Rmd", + output = tempfile()) + usethis::use_data(r_nix_revs, + overwrite = TRUE) +}) + +``` + +```{r} +fusen::inflate(flat_file = "dev/data_doc.Rmd", + vignette_name = NA, + overwrite = TRUE) +``` # Package development tools ## Use once diff --git a/dev/config_attachment.yaml b/dev/config_attachment.yaml new file mode 100644 index 00000000..46e24ecc --- /dev/null +++ b/dev/config_attachment.yaml @@ -0,0 +1,12 @@ +path.n: NAMESPACE +path.d: DESCRIPTION +dir.r: R +dir.v: vignettes +dir.t: tests +extra.suggests: ~ +pkg_ignore: ~ +document: yes +normalize: yes +inside_rmd: no +must.exist: yes +check_if_suggests_is_installed: yes diff --git a/dev/config_fusen.yaml b/dev/config_fusen.yaml new file mode 100644 index 00000000..d0346e7e --- /dev/null +++ b/dev/config_fusen.yaml @@ -0,0 +1,39 @@ +data_doc.Rmd: + path: dev/data_doc.Rmd + state: active + R: R/included-datasets.R + tests: [] + vignettes: [] + inflate: + flat_file: dev/data_doc.Rmd + vignette_name: .na + open_vignette: true + check: true + document: true + overwrite: 'yes' +flat_minimal_package.Rmd: + path: dev/flat_minimal_package.Rmd + state: active + R: R/my_fun.R + tests: tests/testthat/test-my_fun.R + vignettes: vignettes/minimal.Rmd + inflate: + flat_file: dev/flat_minimal_package.Rmd + vignette_name: Minimal + open_vignette: true + check: true + document: true + overwrite: ask +save_r_nix_revs.Rmd: + path: dev/save_r_nix_revs.Rmd + state: active + R: [] + tests: [] + vignettes: vignettes/dev-save_r_nix_revs.Rmd + inflate: + flat_file: dev/save_r_nix_revs.Rmd + vignette_name: dev-save_r_nix_revs + open_vignette: true + check: true + document: true + overwrite: 'yes' diff --git a/dev/data_doc.Rmd b/dev/data_doc.Rmd new file mode 100644 index 00000000..3cdfd863 --- /dev/null +++ b/dev/data_doc.Rmd @@ -0,0 +1,16 @@ +## Included datasets + +```{r function-r_nix_revs, eval = FALSE} +#' r_nix_revs +#' +#' Nix revisions with old R releases +#' +#' @format A data frame with 34 rows and 3 variables: +#' \describe{ +#' \item{ version }{ R version } +#' \item{ revision }{ Nix revision containing this version of R } +#' \item{ date }{ Date when this revision was available } +#' } +#' @source Nix Package Version, by Marcelo Lazaroni +"r_nix_revs" +``` diff --git a/dev/flat_minimal_package.Rmd b/dev/flat_minimal_package.Rmd index 4dc3e436..a578d2e2 100644 --- a/dev/flat_minimal_package.Rmd +++ b/dev/flat_minimal_package.Rmd @@ -43,8 +43,3 @@ test_that("my_fun works", { ``` -```{r development-inflate, eval=FALSE} -# Run but keep eval=FALSE to avoid infinite loop -# Execute in the console directly -fusen::inflate(flat_file = "dev/flat_minimal_package.Rmd", vignette_name = "Minimal") -``` diff --git a/dev/save_r_nix_revs.Rmd b/dev/save_r_nix_revs.Rmd new file mode 100644 index 00000000..175caebc --- /dev/null +++ b/dev/save_r_nix_revs.Rmd @@ -0,0 +1,26 @@ +--- +title: "Get the Nix revisions for old releases of R" +output: html_document +editor_options: + chunk_output_type: console +--- + +To install old versions of R, specific Nix revisions must be used. This tool +[Nix Package Versions](https://lazamar.co.uk/nix-versions/) provides a simple +web-interface to look for packages and get their revisions. + +It is possible to scrape the table and get the data: + +```{r} +library(rvest) +library(dplyr) +library(janitor) + +r_nix_revs <- read_html("https://lazamar.co.uk/nix-versions/?channel=nixpkgs-unstable&package=r") |> + html_element("table") |> + html_table() |> + clean_names() |> + filter(!grepl("wrapper", version)) |> + select(-package) + +``` diff --git a/man/my_fun.Rd b/man/my_fun.Rd new file mode 100644 index 00000000..b69e2839 --- /dev/null +++ b/man/my_fun.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/my_fun.R +\name{my_fun} +\alias{my_fun} +\title{my_fun Title} +\usage{ +my_fun() +} +\value{ +1 +} +\description{ +my_fun Title +} +\examples{ +my_fun() +} diff --git a/man/pipe.Rd b/man/pipe.Rd new file mode 100644 index 00000000..a648c296 --- /dev/null +++ b/man/pipe.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils-pipe.R +\name{\%>\%} +\alias{\%>\%} +\title{Pipe operator} +\usage{ +lhs \%>\% rhs +} +\arguments{ +\item{lhs}{A value or the magrittr placeholder.} + +\item{rhs}{A function call using the magrittr semantics.} +} +\value{ +The result of calling \code{rhs(lhs)}. +} +\description{ +See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. +} +\keyword{internal} diff --git a/man/r_nix_revs.Rd b/man/r_nix_revs.Rd new file mode 100644 index 00000000..bca1f932 --- /dev/null +++ b/man/r_nix_revs.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/included-datasets.R +\docType{data} +\name{r_nix_revs} +\alias{r_nix_revs} +\title{r_nix_revs} +\format{ +A data frame with 34 rows and 3 variables: +\describe{ +\item{ version }{ R version } +\item{ revision }{ Nix revision containing this version of R } +\item{ date }{ Date when this revision was available } +} +} +\source{ +Nix Package Version, by Marcelo Lazaroni +} +\usage{ +r_nix_revs +} +\description{ +Nix revisions with old R releases +} +\keyword{datasets} diff --git a/man/rix-package.Rd b/man/rix-package.Rd new file mode 100644 index 00000000..ac35ecd7 --- /dev/null +++ b/man/rix-package.Rd @@ -0,0 +1,15 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/rix-package.R +\docType{package} +\name{rix-package} +\alias{rix} +\alias{rix-package} +\title{rix: Rix: Reproducible Environments With Nix} +\description{ +Provides helper functions to create reproducible development environments using the Nix package manager. +} +\author{ +\strong{Maintainer}: Bruno Rodrigues \email{brodriguesco@protonmail.com} (\href{https://orcid.org/0000-0002-3211-3689}{ORCID}) + +} +\keyword{internal} diff --git a/tests/testthat.R b/tests/testthat.R new file mode 100644 index 00000000..9a0e6f8b --- /dev/null +++ b/tests/testthat.R @@ -0,0 +1,4 @@ +library(testthat) +library(rix) + +test_check("rix") diff --git a/tests/testthat/test-my_fun.R b/tests/testthat/test-my_fun.R new file mode 100644 index 00000000..e650303d --- /dev/null +++ b/tests/testthat/test-my_fun.R @@ -0,0 +1,5 @@ +# WARNING - Generated by {fusen} from dev/flat_minimal_package.Rmd: do not edit by hand + +test_that("my_fun works", { + +}) diff --git a/vignettes/dev-save_r_nix_revs.Rmd b/vignettes/dev-save_r_nix_revs.Rmd new file mode 100644 index 00000000..16516d87 --- /dev/null +++ b/vignettes/dev-save_r_nix_revs.Rmd @@ -0,0 +1,43 @@ +--- +title: "dev-save_r_nix_revs" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{dev-save_r_nix_revs} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +```{r setup} +library(rix) +``` + + + +To install old versions of R, specific Nix revisions must be used. This tool +[Nix Package Versions](https://lazamar.co.uk/nix-versions/) provides a simple +web-interface to look for packages and get their revisions. + +It is possible to scrape the table and get the data: + + +```{r} +library(rvest) +library(dplyr) +library(janitor) + +r_nix_revs <- read_html("https://lazamar.co.uk/nix-versions/?channel=nixpkgs-unstable&package=r") |> + html_element("table") |> + html_table() |> + clean_names() |> + filter(!grepl("wrapper", version)) |> + select(-package) + +``` + diff --git a/vignettes/minimal.Rmd b/vignettes/minimal.Rmd new file mode 100644 index 00000000..f593393c --- /dev/null +++ b/vignettes/minimal.Rmd @@ -0,0 +1,33 @@ +--- +title: "Minimal" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{minimal} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +```{r setup} +library(rix) +``` + + + + + + +# my_fun + +```{r examples-my_fun} +my_fun() +``` +