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

created a eng_r function which exposes the R engine #1963

Merged
merged 17 commits into from
Mar 11, 2021
Merged

created a eng_r function which exposes the R engine #1963

merged 17 commits into from
Mar 11, 2021

Conversation

abhsarma
Copy link
Contributor

@abhsarma abhsarma commented Feb 10, 2021

I created a separate engine for handling R code blocks, and exported it to make it accessible to users. This was useful in the implementation of our engine --- we are creating a package which allows end-users to declare multiverse analyses (multiple reasonable alternative statistical analysis pipelines) in a flexible and concise manner. Thus, our implementation resulted in a syntax which is not strictly R, but is processed into (multiple sets of) valid R syntax. We want to execute these generated R syntax using knitr to create rendered documents, which is not possible as current implementation does not expose this to the developer.

It can be useful to extend the R syntax --- developers can create custom engines which allows end-users to write commands/syntax which is not strictly in R but can then be processed into R output if necessary.

Example:

r_code <- process_code(options$code) # processes code which is not R to valid R syntax

eng_r(r_code) # outputs which have knitr formatting

@CLAassistant
Copy link

CLAassistant commented Feb 10, 2021

CLA assistant check
All committers have signed the CLA.

Copy link
Owner

@yihui yihui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sounds good to me to factor out the R engine. I just want to make a slight modification, i.e., register this engine via knit_engine$set(R = eng_r) in engine.R. Then you don't need to export the function eng_r, but can access it via knit_engine$get('R'). Would that be okay to you?

BTW, if you use RStudio, please use Ctrl + Shift + B to generate the Rd files. Or just leave out changes in Rd. Thanks!

@abhsarma
Copy link
Contributor Author

Thanks for bringing that up. I've changed things so that eng_r is no longer exported and it works like you said. I also reset the head and tried to leave out changes in the Rd files, but I am not sure why there are still conflicts. Please let me know if I can do anything else

@abhsarma abhsarma requested a review from yihui February 16, 2021 18:52
Copy link
Owner

@yihui yihui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks perfect now. Thanks!

@yihui yihui merged commit ced65ea into yihui:master Mar 11, 2021
@abhsarma
Copy link
Contributor Author

Awesome thank you!

@cderv
Copy link
Collaborator

cderv commented Mar 12, 2021

That is awesome @abhsarma !
it was something I had in mind for a long time ! IMO it simplifies the reading / understanding of code and will allow to do more extension of R engine behavior !

Thank you for this !

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants