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

different way to specify engines {r engine='python'} -> {python} #963

Closed
jankatins opened this issue Feb 27, 2015 · 7 comments
Closed

different way to specify engines {r engine='python'} -> {python} #963

jankatins opened this issue Feb 27, 2015 · 7 comments
Labels
feature Feature requests
Milestone

Comments

@jankatins
Copy link

Re: https://twitter.com/xieyihui/status/571162828528185345

Just because I recently wanted to support '''{python} ('''{r engine='python'} -> '''{python}) in a python port of knitr and had to include that in the regex I use:

    chunk_begin = '^\s*```+\s*{[.]?([a-z]+)\s*(.*)}\s*$'
    chunk_end = '^\s*```+\s*$'
    inline_code = '`([a-z]+) +([^`]+)\s*`'

And then in parser.R:36

      params.src = if (group_pattern(chunk.begin)) {
        tmp <- str_trim(gsub(chunk.begin, '\\2', g[1]))
        engine <- str_trim(gsub(chunk.begin, '\\1', g[1]))
        if(engine != "r"){
            tmp <- paste(tmp, ", engine='",engine,"'"
        }
        tmp
      } else ''

(this is probably not valid R code... :-/ )

@yihui
Copy link
Owner

yihui commented Feb 27, 2015

That sounds like a good idea. I'll think about it. Thanks!

@kevinushey
Copy link

@yihui, do you plan on making this work generally for all language modes, so that e.g. all of the following are valid?

```{python}
```

or

```{css}
```

Just wondering because on the RStudio side it might be nice to have snippet insertions for each form.

@yihui
Copy link
Owner

yihui commented Mar 30, 2015

@kevinushey Yes, it will be a general form like

```{lang}

for all language engines.

@jankatins
Copy link
Author

In the interest of adding all arguments, I would like to add this here, which I found out at my side when I implemented chunk options.

It seems that knitr uses eval to build the plotting chunk options, so valid R code is possible to be included in the options. Even if you use engine="python", the plotting options are still evaluated as R code, so a python True will probably error in rmd (-> TRUE).

IMO this is an argument to keep using {r ... engine="python"}, because the options are "R" and not "python". On the other hand, knitpy uses .pymd and not .rmd as a file extensions, so one could argue that this already is enough to distinguish between r and py...

-> all in all, I still think that file extensions are enough and {lang} would be nice.

@yihui
Copy link
Owner

yihui commented Mar 31, 2015

@JanSchulz Thanks! I'm not trying to throw away {r engine=???}: I just want to add {???} as a shorthand of it. I guess the vast majority of knitr users are R users, so I'm not seriously concerned about the True issue, and I'd encourage them to use your knitpy if they are more comfortable with the Python syntax :)

@yihui yihui added this to the v1.10 milestone Apr 12, 2015
@yihui yihui added the feature Feature requests label Apr 12, 2015
yihui added a commit to yihui/knitr-examples that referenced this issue Apr 12, 2015
@yihui yihui closed this as completed in ad2c994 Apr 12, 2015
yihui added a commit that referenced this issue Apr 12, 2015
@yihui
Copy link
Owner

yihui commented Apr 12, 2015

Done.

@github-actions
Copy link

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@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

No branches or pull requests

3 participants