TERR function RGraph in RinR package failed to display Unicode Characters in the generated graph

TERR function RGraph in RinR package failed to display Unicode Characters in the generated graph

book

Article ID: KB0073339

calendar_today

Updated On:

Products Versions
Spotfire Enterprise Runtime for R 5.0.0 and later
Spotfire Server 10.10.0 or later
Spotfire Enterprise Runtime for R - Server Edition 1.2.0 and later

Description

User has a TERR data function in Spotfire. This TERR data function reads input data table, loads RinR package in TERR, point RinR_R_FULL_PATH to a locally installed Open Source R engine, and use RGraph function to generate Open Source R graphs (like scatterplot, bar plots, etc). The graph is outputted as binary document property in the data function, and it can then be viewed in a Spotfire Analyst visualization.

An example TERR script code to generate the bar plot with RinR RGraph function, is below:

 library(RinR) configureREvaluator(REvaluator, FullPath="C:/Program Files/R/R-3.6.2/bin/R.exe") # options( RinR_R_FULL_PATH = "C:/Program Files/R/R-3.6.2/bin/R.exe" ) myplot <- RGraph({                 barplot(count ~ sex, InputData)},                 data = "InputData",                 display = FALSE)

In a situation where InputData table has Unicode characters/text in the cell values, the R graph generated from RinR RGraph function is unable display the Unicode text correctly. 

For example, the bar plot generated from RGraph with input data containing Japanese text, has the Japanese text un-readable in the graph. 
User-added image

The bar plot generated from Open Source R console with the same dataset, however, is able to display the Japanese text correctly in the graph. 
 d=read.csv("C:/path/to/input/data.csv",header=TRUE,encoding="UTF-8") InputData=d barplot(count ~ sex, InputData)

User-added image
 

Environment

All

Resolution

The problem is due to RinR using an older RDS serialization format that doesn't handle the Japanese Unicode characters properly. 

As a workaround, add the following to the top of the TERR data function (after the library(RinR) call): 
 assign("serializationVersionToRemote", 3, envir=RinR:::RinR.env) assign("serializationVersionFromRemote", 3, envir=RinR:::RinR.env) 
 

That will force RinR to use the latest (version 3) serialization format and resolve the issue.

For example, with below code, the generated graph from RGraph is then able to display the Japanese text in the graph successfully.

 library(RinR) assign("serializationVersionToRemote", 3, envir=RinR:::RinR.env) assign("serializationVersionFromRemote", 3, envir=RinR:::RinR.env) configureREvaluator(REvaluator, FullPath="C:/Program Files/R/R-3.6.2/bin/R.exe") # options( RinR_R_FULL_PATH = "C:/Program Files/R/R-3.6.2/bin/R.exe" ) myplot <- RGraph({                 barplot(count ~ sex, InputData)},                 data = "InputData",                 display = FALSE)

Issue/Introduction

TERR function RGraph in RinR package failed to display Unicode Characters in the generated graph