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

add a helper for automatic naming of unnamed code chunks #2228

Open
3 tasks done
rkb965 opened this issue Feb 11, 2023 · 3 comments
Open
3 tasks done

add a helper for automatic naming of unnamed code chunks #2228

rkb965 opened this issue Feb 11, 2023 · 3 comments
Labels
feature Feature requests

Comments

@rkb965
Copy link

rkb965 commented Feb 11, 2023

Feature request: Could you add automatic naming of code chunks when inserting new chunk?

Justification: I create new code chunks via Ctrl + Alt + I. Sometimes I write sensible names for the code chunks, and sometimes I don't bother and instead leave them unnamed. When I knit and see messages/warnings in, eg, Unnamed Code Chunk 23, I am less likely to investigate whether or not this message/warning needs to be addressed when I have no idea what code chunk it originated from. That's definitely bad practice on my part.

Solution: I am aware of namer but (1) I think the warning re: version control is a bit off-putting as a newer user to git and (2) I think this functionality should be incorporated directly into rmarkdown/knitr. I could envision a small random string of letters or a more human-readable random 2-or-3 word string (eg as GitHub does for new repo naming suggestions). If it adds complexity, I don't think there needs to be any overhead re: ensuring no repeats of names since, when duplicate code chunk names are found, that error is thrown so quickly upon rendering.

Thank you so much for considering this!

I conflate knitr and rmarkdown so apologies if this is the wrong location for this feature request.


By filing an issue to this repo, I promise that

  • I have fully read the issue guide at https://yihui.org/issue/.
  • I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('knitr'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('yihui/knitr').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.

@cderv
Copy link
Collaborator

cderv commented Feb 13, 2023

Thanks for the suggestion !

This would be an issue for the RStudio IDE (https://github.com/rstudio/rstudio) as this is where the CTRL + ALT + I feature is implemented. We can't change anything regarding what will be inserted in the source pane of the IDE from the knitr or rmarkdown package.

I believe this is a great suggestions and you should open there if there are none on that topic already

(2) I think this functionality should be incorporated directly into rmarkdown/knitr

We could do something like namer to "fix" a document by naming the unnamed chunk. Historically, knitr is labelling chunk internally using unamed-chunk-i, i being the chunk number. Hence why it is reported in issue. It is not core to knitr knitting feature though, and it already lives in another R package on CRAN that can easily be used.

We need to think about it. 🤔 @yihui some thoughts about a helper function to modify a Rmd source to add random name to unnamed chunks ?

@rkb965
Copy link
Author

rkb965 commented Feb 13, 2023

Thanks for the clarification, @cderv ! I wasn't confident that this belonged in knitr but it was my best guess (and, not surprisingly, wrong). I'll open a different feature request ticket in rstudio.

I agree that there's a package that solves this issue, but it's such a basic and common problem that I personally think it shouldn't rely on an external package and should instead somehow be smoothly integrated into the user experience.

Thanks for your time and consideration!

@yihui
Copy link
Owner

yihui commented Feb 13, 2023

@yihui some thoughts about a helper function to modify a Rmd source to add random name to unnamed chunks ?

Yes, we can do that. Naming is hard (except for totally random names), though.

@cderv cderv changed the title add automatic naming of code chunks add a helper for automatic naming of unnamed code chunks Feb 13, 2023
@cderv cderv added the feature Feature requests label Feb 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature requests
Projects
None yet
Development

No branches or pull requests

3 participants