Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change coffeescript flags so that code is evaluated, not just compiled #821

Merged
merged 1 commit into from
Jul 29, 2014
Merged

Change coffeescript flags so that code is evaluated, not just compiled #821

merged 1 commit into from
Jul 29, 2014

Conversation

jlburkhead
Copy link

Currently when using engine="coffee" the code is run with the -p flag which prints the compiled code instead of the output.

For example, the following .Rmd file

```{r engine="coffee"}
x = 42
console.log "The answer is ", x
```

compiles to the following markdown

```coffee
x = 42
console.log "The answer is ", x
```

```
## (function() {
##   var x;
##
##   x = 42;
##
##   console.log("The answer is ", x);
##
## }).call(this);
```

By removing the -p flag the code is evaluated and the resulting markdown is

```coffee
x = 42
console.log "The answer is ", x
```

```
## The answer is  42
```

which seems to be the desired output given my experience using knitr with R and python.

@ramnathv
Copy link
Contributor

Interesting. My use case usually is to generate javascript that will dynamically render something on the page as opposed to using coffeescript as a static computational engine. I presume the easiest way to accommodate flags is to allow them to be passed on as chunk options.

@ghost
Copy link
Author

ghost commented Jul 29, 2014

By default it will end up in a code tag in the rendered html, so it won't actually run. Do you have an example of using it to dynamically render something? It still seems like -p should be removed from the default behavior for coffeescript to keep things consistent with the other engine options.

@ramnathv
Copy link
Contributor

I always use it with comment = NA, results = 'asis'. A good example would be d3 code to create an interactive visualization. In this case you want the output to be javascript.

yihui added a commit that referenced this pull request Jul 29, 2014
Change coffeescript flags so that code is evaluated, not just compiled
@yihui yihui merged commit 3c75f75 into yihui:master Jul 29, 2014
@yihui yihui added the Feature label Jul 29, 2014
@yihui yihui added this to the v1.7 milestone Jul 29, 2014
@yihui
Copy link
Owner

yihui commented Jul 29, 2014

It makes more sense not to force -p by default, since it is possible to set engine.opts = '-p' if the user wants to print JavaScript. If I force -p, it is not possible for the user to cancel it, hence I have merged this PR. Thanks!

yihui added a commit to yihui/knitr-examples that referenced this pull request Jul 29, 2014
yihui added a commit that referenced this pull request Jul 29, 2014
yihui added a commit that referenced this pull request Jul 29, 2014
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature Feature requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants