I want to use R-tools for files in Japanese, encode is Shift-JIS.
I think I have to use encoding='cp932' parameter in R script.
But it doesn't work by my trials...
I attached my flow.
Would someone please check my workflow?
Thanks,
Toshi
Solved! Go to Solution.
@SydneyF - I have an R-script that I am using to upload data to a database, however I am running into issues with certain header names that have special characters. I tried some of the work arounds in this chain with no success. The base code is pasted below and the errors are when a header field has /, -, etc. All special characters (inclusing spaces) seem to be changed to . when pulled into the R tool. How can I get them to retain the special characters for the headers?
Thanks,
Matt
if("RPostgreSQL" %in% rownames(installed.packages(),) == FALSE)
{install.packages("RPostgreSQL",repos="http://cran.revolutionanalytics.com")}
library (RPostgreSQL)
value <- read.Alteryx("#4", mode="data.frame")
names(value) <- gsub(x = names(value), "[.]", " ", value)
drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv,
dbname = "XXXXXXX",
host = "XXX.XX.XX.XX",
port = XXXX,
user = "XXXXXXX",
password = "XXXXXXX")
RPostgreSQL::dbSendQuery(con, "TRUNCATE schema.tablename")
name <- c("schema", "tablename")
dbWriteTable(
con = con,
name = name,
value = value,
row.names = FALSE,
append = TRUE,
col.names = FALSE
)
dbDisconnect(con)
write.Alteryx(value, 1)
Hi @MatthewYoung,
When you read data into the R Tool, it creates an R data frame. The column names in an R data frame must be syntactically valid, which for R means that they must start with a letter, and include only letters, numbers, and the special characters . or _. Forward slashes, dashes, spaces, and any other special characters that are not syntactically valid in R will all be converted to a dot.
There are some ways to work around this when using other functions, like read.csv() or data.frame(), however, there is not currently an argument in read.Alteryx() that can be applied to retain the special characters. It looks like someone has posted a product idea for enhancements to the read.Alteryx() function here - I would suggest starring it and commenting with your use case if you would like to see updates to this function as well. Our product managers are very active on the Product Ideas page and are always looking for great new features to add to our software. The more attention an idea gets (i.e., stars and comments) the more likely it is to be considered.
If you would like to read more about special characters in R, please see the following Stackoverflow threads:
https://stackoverflow.com/questions/46437258/why-r-changes-special-characters-in-column-name-to-dots
https://stackoverflow.com/questions/42842031/r-trouble-with-space-and-in-variable-and-column-name
Thanks!
SydneyF