Skip to content

Commit

Permalink
test the new feature introduced in yihui/knitr#963
Browse files Browse the repository at this point in the history
  • Loading branch information
yihui committed Apr 12, 2015
1 parent a0a9a07 commit 3ab7819
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
7 changes: 7 additions & 0 deletions 023-engine-python.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ print(x)
print(x.split(' '))
```

Or use the syntax ```` ```{python} ````:

```{python}
x = 'hello, python world!'
print(x.split(' '))
```

If all the chunks below are python chunks, we can set the engine globally:

```{r setup, include=FALSE}
Expand Down
12 changes: 12 additions & 0 deletions 023-engine-python.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ print(x.split(' '))
## ['hello,', 'python', 'world!']
```

Or use the syntax ```` ```{python} ````:


```python
x = 'hello, python world!'
print(x.split(' '))
```

```
## ['hello,', 'python', 'world!']
```

If all the chunks below are python chunks, we can set the engine globally:


Expand Down
8 changes: 4 additions & 4 deletions 029-engine-Rcpp.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ library(knitr)
opts_chunk$set(cache = TRUE) # because the compilation takes time, let's cache it
```

When the chunk option `engine='Rcpp'` is specified, the code chunk will be compiled through **Rcpp** via `sourceCpp()`:
When the chunk option `engine='Rcpp'` is specified (or you write the chunk header as ```` ```{Rcpp} ````), the code chunk will be compiled through **Rcpp** via `sourceCpp()`:

Test for `fibonacci`:

```{r fibCpp, engine='Rcpp'}
```{Rcpp, fibCpp}
#include <Rcpp.h>
// [[Rcpp::export]]
Expand All @@ -28,7 +28,7 @@ fibonacci(20L)

You can define multiple functions (or helper functions that are not exported) within Rcpp code chunks:

```{r multipleCpp, engine='Rcpp'}
```{Rcpp, multipleCpp}
#include <Rcpp.h>
using namespace Rcpp;
Expand Down Expand Up @@ -60,7 +60,7 @@ List lapplyCpp(List input, Function f) {

If you want to link to code defined in another package (e.g **RcppArmadillo**) then you need to provide an `Rcpp::depends` attribute. For example:

```{r lmCpp, engine='Rcpp'}
```{Rcpp, lmCpp}
// [[Rcpp::depends(RcppArmadillo)]]
#include <RcppArmadillo.h>
Expand Down
2 changes: 1 addition & 1 deletion 029-engine-Rcpp.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@



When the chunk option `engine='Rcpp'` is specified, the code chunk will be compiled through **Rcpp** via `sourceCpp()`:
When the chunk option `engine='Rcpp'` is specified (or you write the chunk header as ```` ```{Rcpp} ````), the code chunk will be compiled through **Rcpp** via `sourceCpp()`:

Test for `fibonacci`:

Expand Down

0 comments on commit 3ab7819

Please sign in to comment.