jacobbien / litr-project

Writing R Packages with Literate Programming
https://jacobbien.github.io/litr-project/
Other
37 stars 3 forks source link

Adjust for "skipped" chunks in `add_chunk_label_hyperlinks()` #37

Closed patrickvossler18 closed 1 year ago

patrickvossler18 commented 1 year ago

This PR addresses the issue described #29 in which chunks with the options include=False or echo=False cause add_chunk_label_hyperlinks() to incorrectly shift the location of chunks because the original implementation assumed a one to one mapping between the indexing of idx_block and original_code. To fix this mapping, I propose we have separate vector of indices for original_code that excludes chunks with the options include=False or echo=False, but is the same length as idx_block. This way, in the loop over the detected chunks in our file, we access the elements in original code that match the elements in the raw file.

To-dos:

jacobbien commented 1 year ago

I think the comments are sufficient in this case, so I've checked that box in your message above.

jacobbien commented 1 year ago

Thanks.

To try out this version of litr, I started by installing it:

devtools::install("litr")

But then I get the error

Error: 'render' is not an exported object from 'namespace:litr'

Looking at litr/R/, I see that no functions are defined.

So then I litr-knitted this version of create-litr.Rmd (using the last release of litr to do so):

litr::render("create-litr.Rmd")

Doing so created a valid R package, but then when I try rendering the create-rknuth.Rmd example, I get the following (showing .Rmd file on left and .html file on right):

Screen Shot 2023-01-04 at 12 06 36 AM

Notice that the referencing is off by 2 (e.g. the ###"b"### label appears two chunks after where it should).

I can see in your version of create-rknuth.html, things looked like they were fixed, so I'm guessing you had a local version working but this didn't make it into the PR?

One more small note: source-files/test-example-files should only have create-rknuth.Rmd, but currently it has create-rknuth.html and rknuth/.