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

Incorrect handling of non ascii chars #160

Open
sbsrouteur opened this issue Apr 16, 2024 · 0 comments
Open

Incorrect handling of non ascii chars #160

sbsrouteur opened this issue Apr 16, 2024 · 0 comments

Comments

@sbsrouteur
Copy link

We encounter an issue with R.Net. I think it is linked to the change of handling of unicode chars in recent R version.

The symptom is as follows :

  • Sourcing a file that has accented chars in it will not work from the app using R.Net. However the file works when sourced fom RStudio
  • Console string printed by the default console are garbled.
    For example if I send print("é") to evaluate to R.Net the console output will be :
print("é")
[1] "ÿþéÿþ"

I have implement a console device implementing a textencoding work around as follows :

    Public Sub WriteConsole(output As String, length As Integer, outputType As ConsoleOutputType) Implements ICharacterDevice.WriteConsole
        Dim E As Encoding = Encoding.GetEncoding(NativeMethods.GetACP)
        Dim UTF8Bytes() As Byte
        Dim S2 As String = output
        Dim Stx = output.IndexOf(ChrW(2))
        Dim Etx = output.IndexOf(ChrW(3))

        Try
            If Stx > 0 And Etx > Stx + 2 Then
                S2 = output.Substring(Stx + 3, Etx - Stx - 3)
                UTF8Bytes = E.GetBytes(S2)
                S2 = Encoding.UTF8.GetString(UTF8Bytes)
            Else
                S2 = output
            End If
        Catch ex As Exception
            'FIX ME add some tracing??
        End Try

        Console.Write(S2)
        Return
    End Sub

This works for fixing the internal output, but I have the feeling that I am doing things wrong here.

Is there a setting in R.Net that needs to be set to have a proper handling of non ascii chars on non us systems with recent version of R runtime?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant