rstudio / rmarkdown

Dynamic Documents for R
https://rmarkdown.rstudio.com
GNU General Public License v3.0
2.88k stars 978 forks source link

Add "do not edit by hand" header to generated files? #1858

Open krlmlr opened 4 years ago

krlmlr commented 4 years ago

So that they show as "read only" in RStudio and perhaps other editors.

Perhaps an option to the default document formats? Can this do any harm?

Screenshot from 2020-07-08 04-43-06

We can't include this in the .Rmd (yet), because the first generated line is empty: https://github.com/r-lib/pillar/blame/dfbb6f74823ab17b0a12fabdfb77ac377100d390/README.md#L1.


By filing an issue to this repo, I promise that

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

yihui commented 4 years ago

I don't know. It could be a breaking change (even if we only mark the .md file as read-only without inserting the comment). If we provide this feature, I think it needs to be an option for users to opt-in rather than opt-out.

krlmlr commented 4 years ago

I don't understand "mark as read-only". Are you suggesting to set the file status to read-only? I'd rather not do that.

The message in RStudio is triggered by the presence of the magic words "do not edit by hand" in the first line of the file. We can either:

cderv commented 2 years ago

Regarding the issue with github_document() format introducing an empty line, I believe this is because of our custom template https://github.com/rstudio/rmarkdown/blob/main/inst/rmarkdown/templates/github_document/resources/default.md

https://github.com/rstudio/rmarkdown/blob/745c1477d02708938febb7065b85b552c7dc420f/inst/rmarkdown/templates/github_document/resources/default.md#L1-L28

There is a lot of newlines introduced and even when everything is false in the template before the body there will be one empty line introduced https://github.com/rstudio/rmarkdown/blob/745c1477d02708938febb7065b85b552c7dc420f/inst/rmarkdown/templates/github_document/resources/default.md#L10-L12

This should probably be included in one of the if. In this case, adding

<!-- README.md is generated from README.Rmd. Please edit that file -->

as first line in the body, or as header-includes

---
output: github_document
header-includes: |
  <!-- README.md is generated from README.Rmd. Please edit that file -->
---

would work.

Would it be better this way ?

emit a line of this form

Regarding this solution, are you suggestion for github_document() only ? for all md_document() ? or for all output ?