Product: TIBCO Spotfire®
TERR function RGraph in RinR package failed to display Unicode Characters in the generated graph
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.
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)
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)
Comments
0 comments
Article is closed for comments.