Skip to content

Commit

Permalink
New 'setup' section (#5)
Browse files Browse the repository at this point in the history
* New 'setup' section

* Remove load_all() since it's interactive

* Start from a blank slate

* Update README

* Use rlang's %||% so it works with older R

* Document
  • Loading branch information
mauro-ixpantia authored Jan 30, 2025
1 parent e013417 commit 4ace5cd
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 0 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
^_pkgdown\.yml$
^docs$
^pkgdown$
^Taskfile\.yml$
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ URL: https://ixpantia.github.io/inc.rtests/
Suggests:
testthat (>= 3.0.0)
Config/testthat/edition: 3
Imports:
rlang
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Generated by roxygen2: do not edit by hand

export(greet)
importFrom(rlang,"%||%")
7 changes: 7 additions & 0 deletions R/inc.rtests-package.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#' @keywords internal
"_PACKAGE"

## usethis namespace: start
#' @importFrom rlang %||%
## usethis namespace: end
NULL
Empty file added R/toy.R
Empty file.
63 changes: 63 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,67 @@ Live.
[example](https://github.com/ixpantia/tower/pull/14/files#diff-8fe6f19b5ce17649a885f3ad91e83f63c1ca2dc91dbcd00fa3bd7e242f80dda7).
* The "incubator" format ([template](https://github.com/dsincubator/template)).

## Setup

> As a developer I want to setup a fresh system so that I can use the devtools workflow to develop an R package.
From an R package in a fresh environment (e.g. on GitHub Codespaces):

* Install R: https://github.com/r-lib/rig

* Ensure to start R from a blank slate:

```bash
# ~/.bash_aliases
alias R="R --no-save --no-restore-data"
```

* Install R-package dependencies: `pak::pak()`

* Install devtools: `pak::pak("devtools")`

* Setup devtools: `usethis::use_devtools()`

```r
# .Rprofile
if (interactive()) {
suppressMessages(require(devtools))
}
```

* Restart R:
* Quit R from the R console: `q()`
* Start R from the terminal: `R`

* Setup the devtools workflow as aliases, then run each `alias` from ther terminal, e.g. `rtest`

```bash
# ~/.bash_aliases
alias rtest="Rscript -e 'devtools::test()'"
alias rdocument="Rscript -e 'devtools::document()'"
alias rcheck="Rscript -e 'devtools::check()'"
```

* Setup the devtools workflow in a [Taskfile.yml](https://taskfile.dev/installation/) then:
* run each `task` from the [extension](https://marketplace.visualstudio.com/items?itemName=task.vscode-task), or
* run each `task` from the terminal, e.g. `task test`.

```yaml
# Taskfile.yml
version: '3'

tasks:
test:
cmds:
- Rscript -e "devtools::test()"
document:
cmds:
- Rscript -e "devtools::document()"
check:
cmds:
- Rscript -e "devtools::check()"
```
For more tasks see Taskfile.yml
</details>
43 changes: 43 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
version: '3'

tasks:
load_all:
cmds:
- Rscript -e "devtools::load_all()"
test:
cmds:
- Rscript -e "devtools::test()"
document:
cmds:
- Rscript -e "devtools::document()"
check:
cmds:
- Rscript -e "devtools::check()"
build_site:
cmds:
- Rscript -e "pkgdown::build_site()"
preview_site:
cmds:
- Rscript -e "pkgdown::preview_site()"
tidy_descrition:
cmds:
- Rscript -e "usethis::use_tidy_description()"
style:
cmds:
- Rscript -e "usethis::use_tidy_style()"
spell_check:
cmds:
- Rscript -e "spelling::spell_check_package()"
test_integration:
cmds:
- Rscript -e "devtools::load_all(); testthat::test_dir('tests/integration')"
package_coverage:
cmds:
- Rscript -e "covr::package_coverage()"
build_readme:
cmds:
- Rscript -e "devtools::build_readme()"
run_examples:
cmds:
- Rscript -e "devtools::run_examples()"

22 changes: 22 additions & 0 deletions man/inc.rtests-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions tests/integration/test-greet.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
test_that("works", {
expect_equal(greet(), "hello world")
})

test_that("con 'Mauro' devuelve hello Mauro", {
expect_equal(greet('Mauro'), "hello Mauro")
})

0 comments on commit 4ace5cd

Please sign in to comment.