Skip to content

Commit a2ea90a

Browse files
committed
try to make qmd vignettes work
1 parent d443caf commit a2ea90a

File tree

11 files changed

+123
-13
lines changed

11 files changed

+123
-13
lines changed
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,17 @@ vignette: >
1212

1313
```{r}
1414
#| include: false
15-
source("_helpers.R")
15+
me <- normalizePath(
16+
if (Sys.getenv("QUARTO_DOCUMENT_PATH") != "") {
17+
Sys.getenv("QUARTO_DOCUMENT_PATH")
18+
} else if (file.exists("benchmarks-funcs.R")) {
19+
getwd()
20+
} else if (file.exists("articles/benchmarks-funcs.R")) {
21+
"articles"
22+
} else {
23+
"vignettes/articles"
24+
})
25+
source(file.path(me, "_helpers.R"))
1626
```
1727

1828
## Annotations {#annotations}
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,17 @@ vignette: >
1212

1313
```{r}
1414
#| include: false
15-
source("_helpers.R")
15+
me <- normalizePath(
16+
if (Sys.getenv("QUARTO_DOCUMENT_PATH") != "") {
17+
Sys.getenv("QUARTO_DOCUMENT_PATH")
18+
} else if (file.exists("benchmarks-funcs.R")) {
19+
getwd()
20+
} else if (file.exists("articles/benchmarks-funcs.R")) {
21+
"articles"
22+
} else {
23+
"vignettes/articles"
24+
})
25+
source(file.path(me, "_helpers.R"))
1626
```
1727

1828
## Execution Model {#execution-model}
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,17 @@ vignette: >
1212

1313
```{r}
1414
#| include: false
15-
source("_helpers.R")
15+
me <- normalizePath(
16+
if (Sys.getenv("QUARTO_DOCUMENT_PATH") != "") {
17+
Sys.getenv("QUARTO_DOCUMENT_PATH")
18+
} else if (file.exists("benchmarks-funcs.R")) {
19+
getwd()
20+
} else if (file.exists("articles/benchmarks-funcs.R")) {
21+
"articles"
22+
} else {
23+
"vignettes/articles"
24+
})
25+
source(file.path(me, "_helpers.R"))
1626
```
1727

1828
Once you have developed your Plumber API, the next step is to find a way to host it. If you haven't dealt with hosting an application on a server before, you may be tempted to run the `api_run()` function from an interactive session on your development machine (either your personal desktop or an RStudio Server instance) and direct traffic there. This is a dangerous idea for a number of reasons:
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,17 @@ vignette: >
1212

1313
```{r}
1414
#| include: false
15-
source("_helpers.R")
15+
me <- normalizePath(
16+
if (Sys.getenv("QUARTO_DOCUMENT_PATH") != "") {
17+
Sys.getenv("QUARTO_DOCUMENT_PATH")
18+
} else if (file.exists("benchmarks-funcs.R")) {
19+
getwd()
20+
} else if (file.exists("articles/benchmarks-funcs.R")) {
21+
"articles"
22+
} else {
23+
"vignettes/articles"
24+
})
25+
source(file.path(me, "_helpers.R"))
1626
```
1727

1828
The [R Programming Language](http://www.R-project.org/) is one of the most dominant programming languages for data analysis and visualization. Still, the world is multilingual, and often R is just a piece of the puzzle. Web services are a common way to allow various systems to interact with one another and the plumber2 R package allows users to expose existing R code as a service available to others on the Web. Plumber2 is best illustrated with an example:
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,17 @@ vignette: >
1212

1313
```{r}
1414
#| include: false
15-
source("_helpers.R")
15+
me <- normalizePath(
16+
if (Sys.getenv("QUARTO_DOCUMENT_PATH") != "") {
17+
Sys.getenv("QUARTO_DOCUMENT_PATH")
18+
} else if (file.exists("benchmarks-funcs.R")) {
19+
getwd()
20+
} else if (file.exists("articles/benchmarks-funcs.R")) {
21+
"articles"
22+
} else {
23+
"vignettes/articles"
24+
})
25+
source(file.path(me, "_helpers.R"))
1626
```
1727

1828
## Moving from plumber
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,17 @@ vignette: >
1212

1313
```{r}
1414
#| include: false
15-
source("_helpers.R")
15+
me <- normalizePath(
16+
if (Sys.getenv("QUARTO_DOCUMENT_PATH") != "") {
17+
Sys.getenv("QUARTO_DOCUMENT_PATH")
18+
} else if (file.exists("benchmarks-funcs.R")) {
19+
getwd()
20+
} else if (file.exists("articles/benchmarks-funcs.R")) {
21+
"articles"
22+
} else {
23+
"vignettes/articles"
24+
})
25+
source(file.path(me, "_helpers.R"))
1626
```
1727

1828
Plumber2 allows you to create APIs by merely decorating your existing R code with special annotations. The example below shows a file named `plumber.R` (the conventional name for Plumber APIs) which defines an API.
@@ -98,7 +108,7 @@ While it is neat to be able to provide results in a variety of formats it is unl
98108

99109
This handler would always produce HTML when called.
100110

101-
```{r, echo=FALSE, results='asis'}
111+
```{r}
102112
#| echo: false
103113
#| results: asis
104114
papi <- api("files/apis/01-02-html.R")
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,17 @@ vignette: >
1212

1313
```{r}
1414
#| include: false
15-
source("_helpers.R")
15+
me <- normalizePath(
16+
if (Sys.getenv("QUARTO_DOCUMENT_PATH") != "") {
17+
Sys.getenv("QUARTO_DOCUMENT_PATH")
18+
} else if (file.exists("benchmarks-funcs.R")) {
19+
getwd()
20+
} else if (file.exists("articles/benchmarks-funcs.R")) {
21+
"articles"
22+
} else {
23+
"vignettes/articles"
24+
})
25+
source(file.path(me, "_helpers.R"))
1626
```
1727

1828
Typically, users define APIs using the "annotations," or special comments in their API source code. It is possible to define a Plumber API programmatically using the same underlying R6 objects that get created automatically when you define your API using annotations. Interacting with Plumber2 at this level can offer more control and specificity about how you want your API to behave. It further opens you up to the full power of [fiery](https://fiery.data-imaginist.com/index.html), upon which plumber2 is build. However, using annotated files will automatically provide you with OpenAPI documentation so in many cases using annotated files will be the obvious starting point.
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,17 @@ vignette: >
1212

1313
```{r}
1414
#| include: false
15-
source("_helpers.R")
15+
me <- normalizePath(
16+
if (Sys.getenv("QUARTO_DOCUMENT_PATH") != "") {
17+
Sys.getenv("QUARTO_DOCUMENT_PATH")
18+
} else if (file.exists("benchmarks-funcs.R")) {
19+
getwd()
20+
} else if (file.exists("articles/benchmarks-funcs.R")) {
21+
"articles"
22+
} else {
23+
"vignettes/articles"
24+
})
25+
source(file.path(me, "_helpers.R"))
1626
```
1727

1828
![](files/images/plumber_output.png){width="45%" style="float:right;"}
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,17 @@ vignette: >
1212

1313
```{r}
1414
#| include: false
15-
source("_helpers.R")
15+
me <- normalizePath(
16+
if (Sys.getenv("QUARTO_DOCUMENT_PATH") != "") {
17+
Sys.getenv("QUARTO_DOCUMENT_PATH")
18+
} else if (file.exists("benchmarks-funcs.R")) {
19+
getwd()
20+
} else if (file.exists("articles/benchmarks-funcs.R")) {
21+
"articles"
22+
} else {
23+
"vignettes/articles"
24+
})
25+
source(file.path(me, "_helpers.R"))
1626
```
1727

1828
![](files/images/plumber_input.png){width="45%" style="float:right;"}
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,17 @@ vignette: >
1212

1313
```{r}
1414
#| include: false
15-
source("_helpers.R")
15+
me <- normalizePath(
16+
if (Sys.getenv("QUARTO_DOCUMENT_PATH") != "") {
17+
Sys.getenv("QUARTO_DOCUMENT_PATH")
18+
} else if (file.exists("benchmarks-funcs.R")) {
19+
getwd()
20+
} else if (file.exists("articles/benchmarks-funcs.R")) {
21+
"articles"
22+
} else {
23+
"vignettes/articles"
24+
})
25+
source(file.path(me, "_helpers.R"))
1626
```
1727

1828
The majority of R programmers have not been trained to give much attention to the security of the code that they write. This is for good reason since running R code on your own machine with no external input gives little opportunity for attackers to leverage your R code to do anything malicious. However, as soon as you expose an API on a network, your concerns and thought process must adapt accordingly.

0 commit comments

Comments
 (0)