Repository navigation
Closed
Description
First off, this package is fantastic, so thank you!
Noticed this bug when running style_pkg() today but reproduced using style_file() on the following text. This is the smallest example I could come up with that still reproduces the error. (Sorry no reprex; wasn't sure if it's possible to use style_file() with reprex::reprex().)
text1 <- "Hauràs de dirigir-te al punt de trobada del grup al que et vulguis unir."
text2 <- "i want to buy an iphone"
text3 <- "Je déteste ne plus avoir de dentifrice."
text <- "A panel of Goldman Sachs employees spent a recent Tuesday night at the Columbia University
faculty club trying to convince a packed room of potential recruits that Wall Street, not Silicon Valley,
was the place to be for computer scientists.\n\n The Goldman employees knew they had an uphill battle.
They were fighting against perceptions of Wall Street as boring and regulation-bound and Silicon Valley as
the promised land of flip-flops, beanbag chairs and million-dollar stock options.\n\n Their argument to the
room of technologically inclined students was that Wall Street was where they could find far more challenging,
diverse and, yes, lucrative jobs working on some of the worlds most difficult technical problems.\n\n
Whereas in other opportunities you might be considering, it is working one type of data or one type of
application, we deal in hundreds of products in hundreds of markets, with thousands or tens of thousands of
clients, every day, millions of times of day worldwide, Afsheen Afshar, a managing director at Goldman Sachs,
told the students."
The trailing quotation marks at the end of the line with text1 and text3 (the two texts that contain accents) are removed leaving:
text1 <- "Hauràs de dirigir-te al punt de trobada del grup al que et vulguis unir.
text2 <- "i want to buy an iphone"
text3 <- "Je déteste ne plus avoir de dentifrice.
text <- "A panel of Goldman Sachs employees spent a recent Tuesday night at the Columbia University
faculty club trying to convince a packed room of potential recruits that Wall Street, not Silicon Valley,
was the place to be for computer scientists.\n\n The Goldman employees knew they had an uphill battle.
They were fighting against perceptions of Wall Street as boring and regulation-bound and Silicon Valley as
the promised land of flip-flops, beanbag chairs and million-dollar stock options.\n\n Their argument to the
room of technologically inclined students was that Wall Street was where they could find far more challenging,
diverse and, yes, lucrative jobs working on some of the worlds most difficult technical problems.\n\n
Whereas in other opportunities you might be considering, it is working one type of data or one type of
application, we deal in hundreds of products in hundreds of markets, with thousands or tens of thousands of
clients, every day, millions of times of day worldwide, Afsheen Afshar, a managing director at Goldman Sachs,
told the students."
The same removal of the trailing quotations happens if those accents are replaced with others, like e.g., umlauts.
I'm running the 1.0.1 development version of the package, r-lib/styler@5733a83.
Activity
run styler::style_pkg() and do some manual restyling
lorenzwalthert commentedon Mar 26, 2018
Thanks @aedobbyn for raising this. So you could also use
style_text()if you wanted to create a reprex. Does the same behaviour occur if you usestyle_text()? I was not able to reproduce this behaviour with the exact same version of styler with bothstyle_text()andstyle_file(). There are two problems that may be related to your issue:The character encoding. Styler is designed to work with utf8. Can you tell me whether the problem persists if you remove all umlaute and other non-english characters and replace them with other characters such as a, b, c, d?
Problems with very longs strings, see Long character string gets truncated #216, Bug with german umlauts #374. But to me, your case seems not to be problematic in that regard and the issues found there wer truncation / removal of characters, but not removal of quotation marks. Can you shorten the value you assign to
textand tell me whether the problem persists.You mentioned that this is the smallest example where the error still persists so I may have missed that your answer to both questions above is no. If so, can you just confirm that? What R version and operating system are you using?
aedobbyn commentedon Mar 26, 2018
Yes, I should have mentioned this but thought I was doing something wrong (and maybe I am). I originally tried to create a reprex with
style_text()but got a different error below.To your question about whether the problem persists when you remove all accented characters: no it does not; the behavior is as expected.
Re: the string length, yes, I should have been more explicit. The length of the the long string is necessary in order to reproduce the example. When it's shortened by even one line the problem goes away.
I'm on MacOS 10.13. R version info below.
lorenzwalthert commentedon Mar 26, 2018
Ok, you got the error with
style_text()because what you inserted above is not code likea <- "hi", but just"hi". So you need double quotes.style_text("'my name is Lorenz'").aedobbyn commentedon Mar 26, 2018
Ahh okay. That did not repro the issue, unfortunately.
lorenzwalthert commentedon Mar 26, 2018
Ok. But the styling still fails with
style_file()right?aedobbyn commentedon Mar 26, 2018
Yes, it does
lorenzwalthert commentedon Mar 26, 2018
If you are using RStudio: can you save the file with utf8 encoding? That is, go to File -> Save with Encoding -> UTF8? And tell me whether it still fails? Likely, this is already your default encoding since you are on Mac. I am also on mac but I have a later R version and possibly a different version of macOS (High sierra).
aedobbyn commentedon Mar 26, 2018
Yeah, UTF8 was the default. Saved it again with that just to make sure and tried
styler::style_file()again. Same behavior as before of dropping the trailing quotations on the accented lines.lorenzwalthert commentedon Apr 3, 2018
We provided a related fix in #384. Can you check whether the problem occurs with that version?
Install relevant branch
before restarting R(Studio) and then re-style.
aedobbyn commentedon Apr 3, 2018
Yep, that worked! The quotations were not removed at the end of the lines with accents.
Tested with the master branch version just to make sure and the problem occurred as usual (trailing quotations were removed).
lorenzwalthert commentedon Apr 3, 2018
Awesome 😊. Will close this when merging #384. Still some minor problems to fix is the there for R 3.1.
aedobbyn commentedon Apr 3, 2018
Great! Thanks for suggesting the solution. Happy to test again once you've merged to make sure.