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

Use R6 representation #33

Merged
merged 14 commits into from
Nov 6, 2020
Merged

Use R6 representation #33

merged 14 commits into from
Nov 6, 2020

Conversation

zkamvar
Copy link
Member

@zkamvar zkamvar commented Nov 4, 2020

I've added an R6 class object with four methods: new, write, reset, and add_md.

I've also added test fixtures and snapshot tests (which are super fun!) (I also may have been on the rOpenSci allcaps when I was writing some of the tests...)

this PR will fix #25, fix #27, and address #28

@zkamvar zkamvar closed this Nov 4, 2020
@zkamvar zkamvar reopened this Nov 4, 2020
Copy link
Member

@maelle maelle left a comment

Choose a reason for hiding this comment

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

This is awesome, thank you! I left a few comments.

Another question that I have is how this should be documented in the README. What approach would we recommend first, R6 or not? In any case at the very top of the README where there's a list of use cases you could add "add an arbitrary new Markdown element like a table".

DESCRIPTION Show resolved Hide resolved
NEWS.md Outdated Show resolved Hide resolved
NEWS.md Show resolved Hide resolved
R/class-yarn.R Show resolved Hide resolved
R/class-yarn.R Outdated Show resolved Hide resolved
R/class-yarn.R Show resolved Hide resolved
R/class-yarn.R Outdated Show resolved Hide resolved
R/class-yarn.R Show resolved Hide resolved
@zkamvar zkamvar changed the title Znk r6 Use R6 representation Nov 4, 2020
R/class-yarn.R Show resolved Hide resolved
Co-authored-by: Maëlle Salmon <maelle.salmon@yahoo.se>
@zkamvar
Copy link
Member Author

zkamvar commented Nov 4, 2020

This is awesome, thank you! I left a few comments.

Another question that I have is how this should be documented in the README. What approach would we recommend first, R6 or not? In any case at the very top of the README where there's a list of use cases you could add "add an arbitrary new Markdown element like a table".

I think we can recommend the R6 approach first since it's arguably more straightforward given that we are defining the namespace prefix in the object. So the first block would turn into this:

# From Markdown to XML
path <- system.file("extdata", "example1.md", package = "tinkr")
y <- yarn$new(path)

library("magrittr")
# transform level 3 headers into level 1 headers
body <- y$body
ns <- y$ns
body %>%
  xml2::xml_find_all(xpath = './/md:heading[@level="3"]', ns) -> headers3

xml2::xml_set_attr(headers3, "level", 1)

y$body <- body

# Back to Markdown
y$write("newmd.md")
file.edit("newmd")

 - stylesheet is now checked for validity
 - path is now an optional argument in `to_md()`
 - to_md() now returns the rendered markdown, invisibly
 - several parts of to_md() were split off into new functions
@zkamvar
Copy link
Member Author

zkamvar commented Nov 4, 2020

Still to do:

  • README
  • test coverage 🙈

@maelle
Copy link
Member

maelle commented Nov 5, 2020

Reg the example I think adding R6 is fine but we might lose some folks if using "->" for assignment 😉

I wonder whether we should add a short list of things that people might enjoy learning about for maximal enjoyment of tinkr

  • XPath
  • XSLT (not crucial if they are ok with the default one)
  • R6 (although reading the docs of tinkr should help)

R/stylesheet.R Show resolved Hide resolved
@zkamvar
Copy link
Member Author

zkamvar commented Nov 5, 2020

Reg the example I think adding R6 is fine but we might lose some folks if using "->" for assignment 😉

come to think of it, for this particular example, we don't even need to use any assignment:

y$body %>%
  xml2::xml_find_all(xpath = './/md:heading[@level="3"]', y$ns) %>%
  xml2::xml_set_attr("level", 1)

y$write("newmd.md")

I wonder whether we should add a short list of things that people might enjoy learning about for maximal enjoyment of tinkr

* XPath

* XSLT (not crucial if they are ok with the default one)

* R6 (although reading the docs of tinkr should help)

YES! Your original link to the XPath page really helped me learn, so I think these extras would also help. It may also be worthwhile thinking about writing up some documentation about how the XSLT stylesheet in {tinkr} works broadly (e.g. that it uses the commonmark namespace and imports the commonmark stylesheet).

I also realized that it's possible to manipulate a stylesheet with {xml2} so that users can change things like bullet point shape

We have checks in place that detect for evaluated chunks, so skipping
based on file name is not necessary. Moreover, this will allow file
connections to be used.
@maelle
Copy link
Member

maelle commented Nov 6, 2020

I opened a few issues

@zkamvar
Copy link
Member Author

zkamvar commented Nov 6, 2020

This is very strange.... I'm able to get the tests to pass on my machine, even with a clean version of the git repo.

@zkamvar
Copy link
Member Author

zkamvar commented Nov 6, 2020

I think this can be merged that the basic elements of the R6 class have been addressed. I think any other modifications should be new PRs.

It's also worthwhile to note that this merge will not change any existing workflows.

@zkamvar zkamvar merged commit 9ee58cb into master Nov 6, 2020
@zkamvar zkamvar deleted the znk-r6 branch November 6, 2020 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use R6 to store the object? Use self-cleaning test fixtures
2 participants