You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Today I discovered the package styler as an alternative to the formatR package.
However as I made some tests I discovered by chance a bug with german umlauts which leads to a cut off at the
position where an umlaut occur. Try to format the following R file (cut off at "Ärger")
For example:
# Test
plant <- setRefClass("plant",
fields = list(name = "character", weight = "numeric", age = "numeric"),
methods = list(
getName = function(x) {
name <<- name
},
getWeight = function(x) {
weight <<- weight
},
getAge = function(x) {
age <<- age
}
)
)
# Here the Ärger!
s <- plant(name = "Corynephorus canescens", weight = 15, age = 3.5)
The test was made on Windows as the OS using the style_file() command.
Windows text file encoding: CP1252
By the way is it possible to suppress the information which are printed to the console?
Ok. I am on macOs, so it's not easy for me to reproduce that. However, styler is designed to work with UTF8 encoded files. If you use RStudio, can you save the file with encoding "UTF-8" and tell me whether it works?
I suspected that the file encoding could be the issue. By changing my default file encoding the formatting works.
However a lot of text editors and IDE's are using the default Windows OS system encoding by default which could cause a lot of headaches and corrupted files. So for windows this should be handled.
I can read in the file with enc::read_lines_enc(..., file_encoding = "latin1") correctly but I think as CP1252 is a superset of "latin1", there are edge cases with incorrect behaviour. @krlmlr do you think we should support more file encodings? Is the package enc limited to utf8 and latin1? If not, we could add an argument file_encoding to the exported style_*() functions. As mentioned above, formatR seems to handle the cases well.
Else the formatting works very fine especially on S4, Ref. and R6 classes whereas formatR fails (also on inline comments). Thank you for this alternative.
Apropos to my question:
Is it possible to suppress the printed R console information from the style_file() function ?
Activity
lorenzwalthert commentedon Mar 14, 2018
Hi @Bio7, thanks for reporting this. Are you using styler 1.0.1? A related bug was fixed there (#329).
Bio7 commentedon Mar 14, 2018
sessionInfo() gives me: styler_1.0.1
Installed from the cran repo.
Bio7 commentedon Mar 14, 2018
R version 3.4.2 (2017-09-28)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 16299)
Matrix products: default
locale:
[1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] styler_1.0.1 Rserve_1.7-3
lorenzwalthert commentedon Mar 14, 2018
Ok. I am on macOs, so it's not easy for me to reproduce that. However, styler is designed to work with UTF8 encoded files. If you use RStudio, can you save the file with encoding "UTF-8" and tell me whether it works?
lorenzwalthert commentedon Mar 14, 2018
I c/p your code, changed to your encoding to CP1252 and I can reproduce your problem.
Bio7 commentedon Mar 14, 2018
I suspected that the file encoding could be the issue. By changing my default file encoding the formatting works.
However a lot of text editors and IDE's are using the default Windows OS system encoding by default which could cause a lot of headaches and corrupted files. So for windows this should be handled.
lorenzwalthert commentedon Mar 14, 2018
I can read in the file with
enc::read_lines_enc(..., file_encoding = "latin1")correctly but I think as CP1252 is a superset of "latin1", there are edge cases with incorrect behaviour.@krlmlr do you think we should support more file encodings? Is the package
enclimited toutf8andlatin1? If not, we could add an argumentfile_encodingto the exportedstyle_*()functions. As mentioned above,formatRseems to handle the cases well.Bio7 commentedon Mar 14, 2018
Else the formatting works very fine especially on S4, Ref. and R6 classes whereas formatR fails (also on inline comments). Thank you for this alternative.
Apropos to my question:
Is it possible to suppress the printed R console information from the style_file() function ?
lorenzwalthert commentedon Mar 14, 2018
Thanks, glad to hear that. It is not (yet) possible. As you probably know, you can always wrap code around a
capture.output()and throw it away.I opened #375 to discuss a new argument in the API.
lorenzwalthert commentedon Mar 14, 2018
I also opened #376 to discuss the support of file encodings.
lorenzwalthert commentedon Mar 23, 2018
Closed in favour of #376.