From 8eb297d5124f170bd2f53b26182b5aa13123b05d Mon Sep 17 00:00:00 2001 From: John Gavin Date: Mon, 12 Aug 2024 21:05:33 +0100 Subject: [PATCH] Update test-coverage.yaml added uploaded action token: ${{ secrets.CODECOV_TOKEN }} Update test-coverage.yaml removed # token: ${{ secrets.CODECOV_TOKEN }} to confirm that it is not useful Update test-coverage.yaml https://github.com/codecov/example-python/blob/main/.github/workflows/ci.yml https://app.codecov.io/gh/JohnGavin/hellow/new Update test-coverage.yaml from https://github.com/r-lib/covr/issues/430 Update test-coverage.yaml v3 -> v4 uses: actions/upload-artifact@v4 Update test-coverage.yaml v4->v3 second try Update test-coverage.yaml trying again Update test-coverage.yaml v4 -> v3 uses: actions/upload-artifact@v3 Update test-coverage.yaml v4 to v3 https://github.com/codecov/codecov-action/issues/1274 Add GitHub links to DESCRIPTION Initial commit --- .Rbuildignore | 10 +++ .github/.gitignore | 1 + .github/workflows/test-coverage.yaml | 65 +++++++++++++++ .gitignore | 6 ++ DESCRIPTION | 17 ++++ LICENSE | 2 + LICENSE.md | 21 +++++ NAMESPACE | 3 + R/isay.R | 19 +++++ _quarto.yml | 19 +++++ about.qmd | 5 ++ docker/Dockerfile | 46 +++++++++++ docker/assets/pre.R | 5 ++ docker/assets/run.sh | 9 +++ docker/hellow_0.0.0.9001.tar.gz | Bin 0 -> 1514 bytes docker/renv.lock | 24 ++++++ hellow.Rproj | 17 ++++ hellow.code-workspace | 11 +++ index.qmd | 76 ++++++++++++++++++ .../qmd/symlink pins_download_local_board.qmd | 1 + inst/qmd/symlink rix.qmd | 1 + inst/qmd/symlink usethis_targets.qmd | 1 + man/isay.Rd | 19 +++++ styles.css | 1 + tests/testthat.R | 12 +++ tests/testthat/test-hello.R | 12 +++ 26 files changed, 403 insertions(+) create mode 100644 .Rbuildignore create mode 100644 .github/.gitignore create mode 100644 .github/workflows/test-coverage.yaml create mode 100644 .gitignore create mode 100644 DESCRIPTION create mode 100644 LICENSE create mode 100644 LICENSE.md create mode 100644 NAMESPACE create mode 100644 R/isay.R create mode 100644 _quarto.yml create mode 100644 about.qmd create mode 100644 docker/Dockerfile create mode 100644 docker/assets/pre.R create mode 100644 docker/assets/run.sh create mode 100644 docker/hellow_0.0.0.9001.tar.gz create mode 100644 docker/renv.lock create mode 100644 hellow.Rproj create mode 100644 hellow.code-workspace create mode 100644 index.qmd create mode 120000 inst/qmd/symlink pins_download_local_board.qmd create mode 120000 inst/qmd/symlink rix.qmd create mode 120000 inst/qmd/symlink usethis_targets.qmd create mode 100644 man/isay.Rd create mode 100644 styles.css create mode 100644 tests/testthat.R create mode 100644 tests/testthat/test-hello.R diff --git a/.Rbuildignore b/.Rbuildignore new file mode 100644 index 0000000..c0009a6 --- /dev/null +++ b/.Rbuildignore @@ -0,0 +1,10 @@ +^hellow\.Rproj$ +^\.Rproj\.user$ +^LICENSE\.md$ +_quarto.yml +about.qmd +hellow.code-workspace +index.qmd +styles.css +^\.github$ +^docker$ 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/test-coverage.yaml b/.github/workflows/test-coverage.yaml new file mode 100644 index 0000000..80f7c68 --- /dev/null +++ b/.github/workflows/test-coverage.yaml @@ -0,0 +1,65 @@ +# 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.yaml + +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: | + covr::codecov(token = "${{ secrets.CODECOV_TOKEN }}") + 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} + + - name: Upload coverage reports to Codecov + # uses: codecov/codecov-action@v4.0.1 + uses: codecov/codecov-action@v4 + with: + # token: ${{ secrets.CODECOV_TOKEN }} + verbose: true + env: + CODECOV_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 + token: ${{ secrets.CODECOV_TOKEN }} + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7c794aa --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.Rproj.user +.Rhistory +.Rdata +.httr-oauth +.DS_Store +.quarto diff --git a/DESCRIPTION b/DESCRIPTION new file mode 100644 index 0000000..599285b --- /dev/null +++ b/DESCRIPTION @@ -0,0 +1,17 @@ +Package: hellow +Title: What the Package Does (One Line, Title Case) +Version: 0.0.0.9001 +Authors@R: + person("John", "Gavin", , "john.b.gavin@gmail.com", role = c("aut", "cre")) +Description: What the package does (one paragraph). +License: MIT + file LICENSE +Encoding: UTF-8 +Roxygen: list(markdown = TRUE) +RoxygenNote: 7.3.2.9000 +Imports: + praise +Suggests: + testthat (>= 3.0.0) +Config/testthat/edition: 3 +URL: https://github.com/JohnGavin/hellow +BugReports: https://github.com/JohnGavin/hellow/issues diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..cb0b02d --- /dev/null +++ b/LICENSE @@ -0,0 +1,2 @@ +YEAR: 2024 +COPYRIGHT HOLDER: john gavin diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..20726fc --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +# MIT License + +Copyright (c) 2024 john gavin + +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/NAMESPACE b/NAMESPACE new file mode 100644 index 0000000..0fe54c9 --- /dev/null +++ b/NAMESPACE @@ -0,0 +1,3 @@ +# Generated by roxygen2: do not edit by hand + +export(isay) diff --git a/R/isay.R b/R/isay.R new file mode 100644 index 0000000..4ce3359 --- /dev/null +++ b/R/isay.R @@ -0,0 +1,19 @@ +# Cmd-Shift-D: Document with Roxygen + +#' say hellp +#' +#' @param size number of time to greet +#' @param ... other args passed to [sample()]. +#' +#' @return a greeting +#' @export +#' +#' @examples +#' + + +isay <- function(size=1, ...) { + message(praise::praise()) + h <- sample(c("Hello", "Hi", "Howdy", "What's up?"), size=size, ...) + return(h) +} diff --git a/_quarto.yml b/_quarto.yml new file mode 100644 index 0000000..5688f32 --- /dev/null +++ b/_quarto.yml @@ -0,0 +1,19 @@ +project: + type: website + +website: + title: "new_project_hellow" + navbar: + left: + - href: index.qmd + text: Home + - about.qmd + +format: + html: + theme: cosmo + css: styles.css + toc: true + + + diff --git a/about.qmd b/about.qmd new file mode 100644 index 0000000..07c5e7f --- /dev/null +++ b/about.qmd @@ -0,0 +1,5 @@ +--- +title: "About" +--- + +About this site diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..b822f0b --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,46 @@ + +# https://blog.stephenturner.us/p/r-package-development-in-positron +# pak::pak('exactextractr') +# pracpac::use_docker() +# pracpac::use_docker(build = FALSE, use_case = "pipeline") +# add the line to install a few additional system utilities using apt, and actually write this shell script. The pracpac package templated out everything else. +# build local docker file with 'hellow' tag +# docker build -t ttmmghmm/hellow:latest -t hellow:0.0.0.9000 ./docker +# docker run --rm ttmmghmm/hellow:latest +# not docker build -f Dockerfile ./docker +# https://stackoverflow.com/questions/34434231/docker-how-to-authenticate-for-docker-push +# docker login --username=ttmmghmm +# not docker login -u="${DOCKER_USERNAME}" -p="${DOCKER_PASSWORD}" +# docker push ttmmghmm/hellow:latest +# docker pull ttmmghmm/hellow:latest + + +# TODO: switch to rix + +FROM rocker/r-ver:latest + +## copy the renv.lock into the image +COPY renv.lock /renv.lock + +## install renv +RUN Rscript -e 'install.packages(c("renv"))' + +## set the renv path var to the renv lib +ENV RENV_PATHS_LIBRARY renv/library + +## restore packages from renv.lock +RUN Rscript -e 'renv::restore(lockfile="/renv.lock", repos=NULL)' + +## copy in built R package +COPY hellow_0.0.0.9001.tar.gz /hellow_0.0.0.9001.tar.gz + +## run script to install built R package from source +RUN Rscript -e 'install.packages("/hellow_0.0.0.9001.tar.gz", type="source", repos=NULL)' + + +RUN apt-get update && apt-get install -y bsdmainutils translate-shell + +COPY assets/run.sh /run.sh +COPY assets/pre.R /pre.R + +CMD ["bash", "/run.sh"] diff --git a/docker/assets/pre.R b/docker/assets/pre.R new file mode 100644 index 0000000..a7fd386 --- /dev/null +++ b/docker/assets/pre.R @@ -0,0 +1,5 @@ + + +library(hellow) + + isay() diff --git a/docker/assets/run.sh b/docker/assets/run.sh new file mode 100644 index 0000000..dc9add0 --- /dev/null +++ b/docker/assets/run.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# https://blog.stephenturner.us/p/r-package-development-in-positron + +# get translation language from first arg: default is french +TOLANG="${1:-:fr}" +HELLO=$(Rscript /pre.R) + +trans "$HELLO" "$TOLANG" diff --git a/docker/hellow_0.0.0.9001.tar.gz b/docker/hellow_0.0.0.9001.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..056c550d2691e73a58ebc539190db985aa8db683 GIT binary patch literal 1514 zcmVz@L=nk zgO4x>L;D;KBK!1%x{T2Cv8@*lqCw~f!+vke@AZen{ucOK8-Pk_Dp8a_MOw`0B`>~! zhiKF3*1dxx8eh;E8$oI}0y*V6!_u3SYS1ZzWjpK&rocHY80_VjE(oMJsKHV#!*rOLm!xB`>w@b1iAPlr*uDio(=LI+L_aU61VZm=y{~_G<4G zeugPW*86+o$-&8lOo~_}yqJyP_33Y&$K+Uiyq+=SopGg|oXU$tToowE>GA7{yJ|iV z8rcoKz89Dw`(!UKh16;UrKDUja#GD^OqmLe4{hXho^C_mOp;5+qL}hoch%Ho39kp# zCkKorYAo`SXSA*>1X(UbGJ*hgr{h2F^aAJwqo_X$BNTl6E3CKha`s1HW*h8O!#kYA zHsB1tC$A_kG=ABq7*9UG5KqZg1NRncweK!f;rsOQ75ne|k#FsP6!d~H7#jN@3>Sr7g^Ul6-X8D0czFsh5BGN`SZ(G6YKzin%DvYAgPm8ClcSyS5ERfdJJkf%9t&xom6`j4+JCs6&GZOH4ybi-ZvN(S$e-SM=I# zOu{|V|Ksj=?8B;f6n$C${k8x1LsO4oz#!OysL}t;t-sM}@AyvQzbF{2)_)lJk+J{L zAZ+aaX6*ksPdX^cX<|7K8B z`8ksyrl5JwKns{j#`G;T&+|ZFmM($HnZnFmDRel9_)gKh%$Vc8_g0K0)0HfM)=V%j zx3#tFS>dpcmQ0y4A!hHwlMYO)A~p%LW2D;dwN1A!%n3lwl)~)UsZ;aOsD3)Gi*2bP zU5XJqt(Qh4%xS|*Zhys9a&2DBLBk^jRr##tw(YpL%}?D4vZ=*(QkN{q52yb*ExP{) z`@f3+{C>Z&{~KQa+5;qaVE_Gf{2%mtKCXWl82{hc|L+eE|4aP;5RNiN6{~BLrLVAO zl)wvE1rg+|pgEhH!h)R9j8nBLXme~lU;7fQsf=BoTN7^0Hf+Pva1%o;XSNSDCudx< zd~Q${^Dj7@1zBPt`C|TAe{&X#gw4+~UR=D}u8sct`N{_^7T&`2dP%biWxC~ourj$h zb)J(OZ@3`$LI2G$wCdim{l9hp6ZZYa{%?H!*Ow7@=Kpd1`?&s5Fl^TU?$-Ys=Ye1I z|AXGm`VT^r|3zW1@&6mj|4vh`>ibY`9HrFOt)>ic#6?170tz#m5~f0~FETM#gFS5s zB#T9k9y&4Z)m(92i)s}+Jk}$Yos6GbUN}WOMuM&?SzZ2ATtZCKhd5>Nh104lTX%Pu`g!|rUOKkvTbP2cpa0zWf5brjABN5O&!+T$ zwbRctG4qsWWs323B{3=RD%CBG7S(?}K;^k)nJ7&>-r+^36pCvpisgwoRi=5F z@wmQnZ1vZUuXBz3+iaPXLOM%st{qBqqtHMD Q4g4tZ56aU~@c=3S07=RWkN^Mx literal 0 HcmV?d00001 diff --git a/docker/renv.lock b/docker/renv.lock new file mode 100644 index 0000000..add23c0 --- /dev/null +++ b/docker/renv.lock @@ -0,0 +1,24 @@ +{ + "R": { + "Version": "4.4.1", + "Repositories": [ + { + "Name": "ropenscireviewtools", + "URL": "https://ropensci-review-tools.r-universe.dev" + }, + { + "Name": "CRAN", + "URL": "https://cloud.r-project.org" + } + ] + }, + "Packages": { + "praise": { + "Package": "praise", + "Version": "1.0.0", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "a555924add98c99d2f411e37e7d25e9f" + } + } +} diff --git a/hellow.Rproj b/hellow.Rproj new file mode 100644 index 0000000..aaa62a5 --- /dev/null +++ b/hellow.Rproj @@ -0,0 +1,17 @@ +Version: 1.0 + +RestoreWorkspace: No +SaveWorkspace: No +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +Encoding: UTF-8 + +AutoAppendNewline: Yes +StripTrailingWhitespace: Yes +LineEndingConversion: Posix + +BuildType: Package +PackageUseDevtools: Yes +PackageInstallArgs: --no-multiarch --with-keep.source +PackageRoxygenize: rd,collate,namespace diff --git a/hellow.code-workspace b/hellow.code-workspace new file mode 100644 index 0000000..58e3a9b --- /dev/null +++ b/hellow.code-workspace @@ -0,0 +1,11 @@ +{ + "folders": [ + { + "path": "hellow" + }, + { + "path": "." + } + ], + "settings": {} +} diff --git a/index.qmd b/index.qmd new file mode 100644 index 0000000..337c4d7 --- /dev/null +++ b/index.qmd @@ -0,0 +1,76 @@ +--- +params: + source_url: "https://blog.stephenturner.us/p/r-package-development-in-positron" +title: "r-package-development-in-positron" +--- + +This is a Quarto website. + +To learn more about Quarto websites visit . + +# usethis ++ dependency management, ++ DESCRIPTION file manipulation, ++ .R and test file creation, ++ data-raw creation, ++ vignettes, ++ pkgdown, ++ GitHub actions ... + +```{r, eval = FALSE} +usethis::create_packagesw("hellow") +usethis::use_mit_license("john gavin") +usethis::use_package("praise") +# +# Cmd-Shift-D: Document with Roxygen +# +devtools::document() +# cmd-shift-E +devtools::check() +# RStudio keyboard shortcut cmd-shift-B +devtools::build() +pak::local_install() + +usethis::use_test("hello") +# cmd-shift-T +devtools::test() + +``` + ++ RStudio uses `R CMD INSTALL` ++ Positron uses `pak::local_install()` + +## covr ++ https://covr.r-lib.org/ + +```{r} +library(covr) +report() # requries DT +# or +if (interactive()) { + # covr::report(covr::package_coverage()) + usethis::use_github_action("test-coverage") +} +``` + +## pracpac ++ R Packaging with Docker + +```{r} +# pak::pak('pracpac') +# add renv.lock file and a Dockerfile +pracpac::use_docker() # analyzes package DESCRIPTION +``` ++ build renv lock file + + captures versions of dependent packages installed + + writes Dockerfile builds R package ++ install all dependencies from renv lock file + + guarantees dependent pkgs versions install in Docker image ++ templates out pre- and post-processing R scripts ++ shell script that will drive the analysis + +## workflow ++ https://www.tidyverse.org/blog/2017/12/workflow-vs-script/ +```{r} +library(here) +``` diff --git a/inst/qmd/symlink pins_download_local_board.qmd b/inst/qmd/symlink pins_download_local_board.qmd new file mode 120000 index 0000000..5fe4f45 --- /dev/null +++ b/inst/qmd/symlink pins_download_local_board.qmd @@ -0,0 +1 @@ +/Users/johngavin/docs_gh/rix/inst/qmd/pins_download_local_board.qmd \ No newline at end of file diff --git a/inst/qmd/symlink rix.qmd b/inst/qmd/symlink rix.qmd new file mode 120000 index 0000000..2cfa8ea --- /dev/null +++ b/inst/qmd/symlink rix.qmd @@ -0,0 +1 @@ +/Users/johngavin/docs_gh/rix/inst/qmd/rix.qmd \ No newline at end of file diff --git a/inst/qmd/symlink usethis_targets.qmd b/inst/qmd/symlink usethis_targets.qmd new file mode 120000 index 0000000..da151ba --- /dev/null +++ b/inst/qmd/symlink usethis_targets.qmd @@ -0,0 +1 @@ +/Users/johngavin/docs_gh/rix/inst/qmd/usethis_targets.qmd \ No newline at end of file diff --git a/man/isay.Rd b/man/isay.Rd new file mode 100644 index 0000000..ccfe030 --- /dev/null +++ b/man/isay.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/isay.R +\name{isay} +\alias{isay} +\title{say hellp} +\usage{ +isay(size = 1, ...) +} +\arguments{ +\item{size}{number of time to greet} + +\item{...}{other args passed to \code{\link[=sample]{sample()}}.} +} +\value{ +a greeting +} +\description{ +say hellp +} diff --git a/styles.css b/styles.css new file mode 100644 index 0000000..2ddf50c --- /dev/null +++ b/styles.css @@ -0,0 +1 @@ +/* css styles */ diff --git a/tests/testthat.R b/tests/testthat.R new file mode 100644 index 0000000..4806b2e --- /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(hellow) + +test_check("hellow") diff --git a/tests/testthat/test-hello.R b/tests/testthat/test-hello.R new file mode 100644 index 0000000..7a09f0e --- /dev/null +++ b/tests/testthat/test-hello.R @@ -0,0 +1,12 @@ +# https://blog.stephenturner.us/p/r-package-development-in-positron + +test_that("multiplication works", { + expect_equal(2 * 2, 4) +}) +test_that("isay", { + expect_message(res <- isay()) + expect_identical(length(res), 1L) + expect_message(res <- isay(50, replace = TRUE)) + expect_identical(length(res), 50L) + expect_error(isay(50)) +})