jumpingrivers / namer

R package :package: for labelling chunks of RMarkdown files! :boom:
https://jumpingrivers.github.io/namer/
Other
94 stars 11 forks source link

Add argument to **unname_all_chunks** specifying which chunks to unname #22

Closed HanOostdijk closed 5 years ago

HanOostdijk commented 5 years ago

The current version of unname_all_chunks removes all chunk labels except setup.

My proposal is to add an argument chunk_name_prefix (chunk name prefix) that when used will indicate which labels will be unnamed by specifying the prefix of these labels.
The default value for this argument is NULL and in that case the current processing will be done: all labels removed except setup.
For the two cases an example is given in the documentation of the function unname_all_chunks.

Use case: I sometimes refer to existing labels by using the chunk option ref.label . For an example of ref.label see e.g. Chunk Reference/Macro . After using name_chunks I have a set with 'own' labels and a set with 'generated' labels. When I later decide that I want to insert new chunks, I would prefer to unname only the 'generated' labels and then apply name_chunks again. With the suggested change, this can be done by specifying as chunk_name_prefix 'the filename with extension stripped' followed with a '-' (dash) that is used in name_chunks.

Apart from unname_all_chunks I also inserted a second named chunk in example4.Rmd in the example folder.

I am not very familiar with the PR process. Let me know when I made mistakes.

Edited:

coveralls commented 5 years ago

Pull Request Test Coverage Report for Build 74


Totals Coverage Status
Change from base Build 68: 0.2%
Covered Lines: 100
Relevant Lines: 103

💛 - Coveralls
HanOostdijk commented 5 years ago

Following up on the coverage test I see that I will have to add to
.\namer\tests\testthat\test-unname_all_chunks.R the case that the ch_n_p argument is not NULL.

maelle commented 5 years ago

:wave: @HanOostdijk, thanks for your PR! It is a generally welcome feature, I'll comment about details.

maelle commented 5 years ago

I'd prefer the name of the argument to be longer and therefore more explicit e.g. chunk_name_prefix. By the way, could you describe your use case for that?

maelle commented 5 years ago

@HanOostdijk I've pushed minimal changes to your branch and will merge if you agree with my adding you as contributor to DESCRIPTION. I did that via desc::desc_add_author_gh("HanOostdijk") so hopefully the info is correct.

maelle commented 5 years ago

One last thing actually, could you please add a paragraph about your use case in the vignette and README after "There's also name_chunks for use on a single R Markdown file; and unname_all_chunks to unname all chunks of a single R Markdown file which can be useful when cleaning your chunk labels."? Thanks!