Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Query Editor R Script Text Type Issues

Hello!

 

Query Editor R Script is changing the data type of text columns to integer automatically.

By business rule, the data must remain with the same type that was specified before running the R script.

 

Fields as text type:

 Data source

 

R script passing the data without any transformation:

 

R passing the data without any transformation

 

Data output with data type changed:

 

Data type changed

 

Code generated automatically by R saved in folder 'C:/Users/x/AppData/Local/Radio/RScriptWrapper_83e78459-95e6-46bb-b903-5cf7ae45dd6a':

 

# Prolog - Auto Generated #
# To run this script, open it with an R editor with UTF-8 encoding and uncomment the following line(s):
# Sys.setenv(RPackagesLibrariesDirectory = 'C:/Users/x/AppData/Local/Radio/Library')
# Sys.setenv(RScriptWrapperWorkingDirectory = 'C:/Users/x/AppData/Local/Radio/RScriptWrapper_83e78459-95e6-46bb-b903-5cf7ae45dd6a')
.libPaths( c( Sys.getenv('RPackagesLibrariesDirectory'), .libPaths() ))
# Input load. Please do not change #
setwd(Sys.getenv('RScriptWrapperWorkingDirectory'))
`dataset` = read.csv('input_df_6ebc0c50-ee6b-475f-952f-c15af44c5915.csv', check.names = FALSE, encoding = "UTF-8", blank.lines.skip = FALSE);
# Original Script. Please update your script content here and once completed copy below section back to the original editing window #

output <- dataset

# Epilog - Auto Generated  #
rm(dataset)
setwd(Sys.getenv('RScriptWrapperWorkingDirectory'))
rScriptWrapper_dataFrames <- list()
if (length(sapply(mget(ls(), .GlobalEnv), is.data.frame)) > 0 )
{
rScriptWrapper_dataFrames <- ls()[sapply(mget(ls(), .GlobalEnv), is.data.frame)]
for(x in rScriptWrapper_dataFrames) {assign(x, as.data.frame(get(x)))}
}
rScriptWrapper_options = getOption('save.image.defaults')
save(list = rScriptWrapper_dataFrames, file = "globalEnv.rdata", version = rScriptWrapper_options$version, ascii = FALSE, compress = TRUE)

 

Power BI's prolog code is using the function read.table to load the flat file without any parameter about data types of the source. The problem is being circumvented by reloading the file by the read_delim function with column definitions parameters for char type.

Status: Accepted
Comments
v-haibl-msft
Employee

@alexandrevv

 

I can repro the same issue as you. I’ve reported it internally to Power BI Team: CRI 37520685
I’ll post here once I get any update about it.

 

Best Regards,
Herbert

Vicky_Song
Impactful Individual
Status changed to: Accepted
 
v-haibl-msft
Employee

@alexandrevv

 

Currently a workaround for this is to convert back integers to string in R script by using toString method.

 

Best Regards,
Herbert

alexandrevv
Regular Visitor

I think that in this case I'll lose padding zeros. Am I correct?