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

.Rd files are forcibly rewritten with LF ending on Windows #989

Closed
krlmlr opened this issue Nov 25, 2019 · 7 comments · Fixed by #1003 or #1044
Closed

.Rd files are forcibly rewritten with LF ending on Windows #989

krlmlr opened this issue Nov 25, 2019 · 7 comments · Fixed by #1003 or #1044

Comments

@krlmlr
Copy link
Member

@krlmlr krlmlr commented Nov 25, 2019

despite of what's announced in the NEWS and in #841.

To reproduce:

  • Clone any package on Windows
  • Run unix2dos man/*.Rd
  • Run devtools::document()

I believe this is because write_if_different() already receives character strings with embedded newlines, and write_lines() doesn't convert them to the detected newlines.

@hadley
Copy link
Member

@hadley hadley commented Nov 26, 2019

@jimhester can you please take a look?

@kent37
Copy link

@kent37 kent37 commented Dec 6, 2019

This is really annoying. For a project created on Windows, with .Rd files created by roxygen2, after updating to roxygen2 7.0.2 and running CMD check, all the .Rd files have new line endings.

@hadley
Copy link
Member

@hadley hadley commented Dec 7, 2019

@krlmlr could you please try out #1003 and see if it works for you?

@krlmlr
Copy link
Member Author

@krlmlr krlmlr commented Dec 7, 2019

Works for me, but produces bogus Writing xxx.Rd messages. Would you like me to look into removing these?

@sz-cgt
Copy link

@sz-cgt sz-cgt commented Dec 10, 2019

Just ran devtools::install_github("r-lib/roxygen2") and generated documentation on a Windows only project.

Still seeing \n instead of \r\n in the generared .Rd files

Before:

$ head -2 man/client.Rd | od -c
0000000   %       G   e   n   e   r   a   t   e   d       b   y       r
0000020   o   x   y   g   e   n   2   :       d   o       n   o   t
0000040   e   d   i   t       b   y       h   a   n   d  \r  \n   %
0000060   P   l   e   a   s   e       e   d   i   t       d   o   c   u
0000100   m   e   n   t   a   t   i   o   n       i   n       R   /   R
0000120   6   -   c   l   i   e   n   t   .   R  \r  \n

After devtools::document(roclets = c('rd', 'collate', 'namespace', 'vignette'))

$ head -2 man/client.Rd | od -c
0000000   %       G   e   n   e   r   a   t   e   d       b   y       r
0000020   o   x   y   g   e   n   2   :       d   o       n   o   t
0000040   e   d   i   t       b   y       h   a   n   d  \n   %       P
0000060   l   e   a   s   e       e   d   i   t       d   o   c   u   m
0000100   e   n   t   a   t   i   o   n       i   n       R   /   R   6
0000120   -   c   l   i   e   n   t   .   R  \n

@hadley
Copy link
Member

@hadley hadley commented Dec 10, 2019

@sz-cgt you'll need to install from the PR: devtools::install_github("r-lib/roxygen2#1003")

@sz-cgt
Copy link

@sz-cgt sz-cgt commented Dec 10, 2019

Oops. Thanks. The PR works for me

gaborcsardi added a commit that referenced this issue Feb 10, 2020
We need to move the detection of line endings
upstream a bit, to be able to tell if the
newly generated contents is different from the
current one, in write_if_different().

This means that we need to paste() the contents
together in write_if_different(). Consequently,
we might as well remove the paste()-ing from
same_contents(), as write_if_different() always
calls it with the paste()-d contents.

Also, if we paste() already upstream, then
we might as well use writeBin() to write out
the contents, instead of write_lines(), especially
because write_lines() would add an extra empty line.
write_lines() is still kept, and used in some
code paths, and it can also do EOL-detection,
although this feature is not used currently.

Another benefit of this refactoring is that we
also move enc2utf8() upstream, this should clearly
happen before we check if the new contents is
different.

Added test cases as well.

Fixes #989, supersedes #1003.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants