Skip to content

Bug with german umlauts #374

Closed
Closed

Description

@Bio7

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?

Activity

  1. lorenzwalthert commented on Mar 14, 2018

    @lorenzwalthert
    Collaborator

    Hi @Bio7, thanks for reporting this. Are you using styler 1.0.1? A related bug was fixed there (#329).

  2. Bio7 commented on Mar 14, 2018

    @Bio7
    Author

    sessionInfo() gives me: styler_1.0.1
    Installed from the cran repo.

  3. Bio7 commented on Mar 14, 2018

    @Bio7
    Author

    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

  4. lorenzwalthert commented on Mar 14, 2018

    @lorenzwalthert
    Collaborator

    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?

  5. lorenzwalthert commented on Mar 14, 2018

    @lorenzwalthert
    Collaborator

    I c/p your code, changed to your encoding to CP1252 and I can reproduce your problem.

  6. Bio7 commented on Mar 14, 2018

    @Bio7
    Author

    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.

  7. lorenzwalthert commented on Mar 14, 2018

    @lorenzwalthert
    Collaborator

    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.

  8. Bio7 commented on Mar 14, 2018

    @Bio7
    Author

    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 ?

  9. lorenzwalthert commented on Mar 14, 2018

    @lorenzwalthert
    Collaborator

    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.

    silent_style_file <- function(...) {
      msg <- capture.output(style_file(...))
    
    }

    I opened #375 to discuss a new argument in the API.

  10. lorenzwalthert commented on Mar 14, 2018

    @lorenzwalthert
    Collaborator

    I also opened #376 to discuss the support of file encodings.

  11. lorenzwalthert commented on Mar 23, 2018

    @lorenzwalthert
    Collaborator

    Closed in favour of #376.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions