Skip to content

Commit

Permalink
Merge pull request #8 from ThinkR-open/fix-ploom
Browse files Browse the repository at this point in the history
Fix ploom
  • Loading branch information
ALanguillaume authored Jan 4, 2023
2 parents 1c6f9e5 + ed31481 commit f348729
Show file tree
Hide file tree
Showing 21 changed files with 197 additions and 59 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
^README\.Rmd$
^cran-comments\.md$
^dev$
^\.github$
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
49 changes: 49 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@ Imports:
cli,
fs,
here,
plumber,
rlang,
rstudioapi,
usethis,
utils,
yaml
Suggests:
httr,
plumber,
pkgload,
rcmdcheck,
testthat (>= 3.0.0),
withr
Config/testthat/edition: 3
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.1
RoxygenNote: 7.2.3
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ importFrom(rstudioapi,openProject)
importFrom(usethis,create_project)
importFrom(usethis,use_r)
importFrom(usethis,use_test)
importFrom(utils,file.edit)
importFrom(utils,getFromNamespace)
importFrom(yaml,read_yaml)
importFrom(yaml,write_yaml)
1 change: 0 additions & 1 deletion R/create_pipework.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ create_mariobox <- function(
overwrite = FALSE,
package_name = basename(path)
) {

# if (check_name) {
# cat_rule("Checking package name")
# getFromNamespace("check_package_name", "usethis")(package_name)
Expand Down
4 changes: 4 additions & 0 deletions R/dep_port.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#' @noRd
#' @importFrom utils file.edit
usethis_use_r <- function(
name,
pkg = ".",
Expand All @@ -24,6 +26,8 @@ usethis_use_r <- function(
file.edit(name)
}
}
#' @noRd
#' @importFrom utils file.edit
usethis_use_test <- function(
name = NULL,
pkg = ".",
Expand Down
2 changes: 1 addition & 1 deletion R/new_api.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#' Launch the API
#'
#'
#' @param yaml_file path to the yaml
#' @importFrom plumber Plumber
#' @importFrom yaml read_yaml
Expand Down
3 changes: 2 additions & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ cat_mariobox_yaml <- function(path_pipo) {
<!-- badges: start -->
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![CRAN status](https://www.r-pkg.org/badges/version/mariobox)](https://CRAN.R-project.org/package=mariobox)
[![R-CMD-check](https://github.com/ThinkR-open/mariobox/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ThinkR-open/mariobox/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->

[DISCLAIMER] This is a Work In Progress, please use at your own risk.
Expand Down Expand Up @@ -188,4 +189,4 @@ readLines(
"plumber.R"
)
) |> cat(sep = "\n")
```
```
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![CRAN
status](https://www.r-pkg.org/badges/version/mariobox)](https://CRAN.R-project.org/package=mariobox)
[![R-CMD-check](https://github.com/ThinkR-open/mariobox/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ThinkR-open/mariobox/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->

\[DISCLAIMER\] This is a Work In Progress, please use at your own risk.
Expand Down Expand Up @@ -44,8 +45,8 @@ create_mariobox(
open = FALSE
)
── Creating dir ────────────────────────────────────────────────────────────────
Creating '/var/folders/5z/rm2h62lj45d332kfpj28c8zm0000gn/T/RtmpP86EN6/pipoac8920906d46/'
Setting active project to '/private/var/folders/5z/rm2h62lj45d332kfpj28c8zm0000gn/T/RtmpP86EN6/pipoac8920906d46'
Creating '/tmp/RtmpjFWgLO/pipo1d75618a38d99/'
Setting active project to '/tmp/RtmpjFWgLO/pipo1d75618a38d99'
Creating 'R/'
Writing a sentinel file '.here'
Build robust paths within your project via `here::here()`
Expand All @@ -55,14 +56,14 @@ create_mariobox(
── Copying package skeleton ────────────────────────────────────────────────────
Copied app skeleton
── Done ────────────────────────────────────────────────────────────────────────
A new mariobox named pipoac8920906d46 was created at /private/var/folders/5z/rm2h62lj45d332kfpj28c8zm0000gn/T/RtmpP86EN6/pipoac8920906d46 .
A new mariobox named pipo1d75618a38d99 was created at /tmp/RtmpjFWgLO/pipo1d75618a38d99 .
```

By default, you’ll find the following structure:

``` r
fs::dir_tree(path_pipo)
/var/folders/5z/rm2h62lj45d332kfpj28c8zm0000gn/T//RtmpP86EN6/pipoac8920906d46
/tmp/RtmpjFWgLO/pipo1d75618a38d99
├── DESCRIPTION
├── NAMESPACE
├── R
Expand Down Expand Up @@ -95,7 +96,7 @@ then do a little bit of its magic and parse this YAML to build the
health_get:
methods: GET
path: /health
handler: health
handler: get_health

### Add/Remove endpoints

Expand Down Expand Up @@ -148,7 +149,7 @@ add_get(

``` r
fs::dir_tree(path_pipo)
/var/folders/5z/rm2h62lj45d332kfpj28c8zm0000gn/T//RtmpP86EN6/pipoac8920906d46
/tmp/RtmpjFWgLO/pipo1d75618a38d99
├── DESCRIPTION
├── NAMESPACE
├── R
Expand Down Expand Up @@ -179,7 +180,7 @@ The YALML is automatically updated:
health_get:
methods: GET
path: /health
handler: health
handler: get_health
allo_get:
methods: GET
path: /allo
Expand All @@ -200,7 +201,7 @@ remove_endpoint(

``` r
fs::dir_tree(path_pipo)
/var/folders/5z/rm2h62lj45d332kfpj28c8zm0000gn/T//RtmpP86EN6/pipoac8920906d46
/tmp/RtmpjFWgLO/pipo1d75618a38d99
├── DESCRIPTION
├── NAMESPACE
├── R
Expand Down Expand Up @@ -230,7 +231,7 @@ The YALML is automatically updated:
health_get:
methods: GET
path: /health
handler: health
handler: get_health
hey_get:
methods: GET
path: /hey
Expand All @@ -256,8 +257,8 @@ your function.
This format might seem weird, but the idea is to separate the concerns
in the following format:

- METHOD_NAME() will handle the http elements (login, headers..)
- METHOD_NAME_f() will be a standard function returning data.
- METHOD_NAME() will handle the http elements (login, headers..)
- METHOD_NAME_f() will be a standard function returning data.

That way, you can handle the data manipulation function just like a
plain standard one, test it, interact with it, etc, without having to
Expand All @@ -279,7 +280,7 @@ can deploy using this file.

``` r
build_plumber_file(pkg = path_pipo)
Loading pipoac8920906d46
Loading pipo1d75618a38d99
plumber.R file created
```

Expand All @@ -293,7 +294,7 @@ This will produce the following file:
#* @get /health
health
get_health
#* @get /hey
get_hey
27 changes: 25 additions & 2 deletions dev/dev_history.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
attachment::att_amend_desc(
extra.suggests = c(
# Those packages are needed for test on marioboxexample to work
"plumber",
"httr",
"yaml",
# Extra dev dependencies
"pkgload",
NULL
),
pkg_ignore = c(
# Extra dev dependencies
"pkgload",
NULL
)
)
Expand All @@ -18,8 +23,26 @@ devtools::check()

devtools::test()


## Project template

marioboxexample_path <- normalizePath("inst/marioboxexample/")

attachment::att_amend_desc(
path = marioboxexample_path
)

devtools::test(
pkg = marioboxexample_path
)

### Setup ----------------------------------------------------------------------

.use_r_with_test("create_mariobox")
.use_r_with_test("utils")
.use_r_with_test("manage_endpoints")


## CI

usethis::use_github_action_check_standard()
12 changes: 3 additions & 9 deletions inst/marioboxexample/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,13 @@ Package: marioboxexample
Title: A cunning plumber API
Version: 0.0.0.9000
Authors@R:
person(given = "firstname",
family = "lastname",
role = c("aut", "cre"),
email = "[email protected]")
person("firstname", "lastname", , "[email protected]", role = c("aut", "cre"))
Description: What the package does (one paragraph).
License: What license is it under?
Imports:
mariobox,
plumber,
yaml
mariobox
Suggests:
httr,
testthat
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.1
RoxygenNote: 7.2.3
3 changes: 1 addition & 2 deletions inst/marioboxexample/NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Generated by roxygen2: do not edit by hand

export(get_health)
export(run_api)
importFrom(plumber,Plumber)
importFrom(yaml,read_yaml)
2 changes: 1 addition & 1 deletion inst/marioboxexample/R/get_health.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
get_health <- function(req, res) {
mariobox::mario_log(
method = "GET",
name = "health"
name = "health"
)
get_health_f()
}
Expand Down
8 changes: 6 additions & 2 deletions inst/marioboxexample/R/run_plumber.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
#'
#' @export
run_api <- function() {
generate_api()$run()
}

generate_api <- function() {
mariobox::new_api(
yaml_file = system.file(
"mariobox.yml",
package = "marioboxexample"
)
)$run()
}
)
}
14 changes: 14 additions & 0 deletions inst/marioboxexample/man/get_health.Rd

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

2 changes: 1 addition & 1 deletion inst/marioboxexample/tests/testthat/test-health.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
test_that("health_f() works", {
expect_equal(
health_f(),
get_health_f(),
"ok"
)
})
4 changes: 2 additions & 2 deletions inst/marioboxexample/tests/testthat/test-run_plumber.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test_that("new_api() works", {
api <- new_api()
test_that("generate_api() works", {
api <- generate_api()
expect_s3_class(
api,
c("Plumber", "Hookable", "R6")
Expand Down
17 changes: 17 additions & 0 deletions mariobox.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX

BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
Loading

0 comments on commit f348729

Please sign in to comment.