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.

Reply
vitexo87
Post Prodigy
Post Prodigy

R script error when exporting data

I have an R script that aims to export the data of a report to excel already handling the export problems (special characters, formatting errors among others).

 

Below is the script and error, I already installed several packages in my R studio but the error persists.

 

# Write.csv (dataset.file = "PowerBIExport.csv")
"Write.table (trim (dataset), file =" C: /Users/vitor.oliveira/Desktop/teste.txt ", sep =" \ t ", row.names = FALSE)

 

Error Message:
R. Script Error
Error in is.data.frame (x): could not find the function "trim"
Calls: write.table -> is.data.frame
Execution stopped

20 REPLIES 20
alanhodgson
Solution Supplier
Solution Supplier

Hey @vitexo87,

 

Looks like that trim function doesn't exist. Try the following, it uses the "stringr" package:

 

library(stringr) 

# Write.csv (dataset.file = "PowerBIExport.csv")
"Write.table (str_trim (dataset), file ="C: /Users/vitor.oliveira/Desktop/teste.txt ", sep =" \ t ", row.names = FALSE)

 Hope this helps,

 

Alan

 

 

@alanhodgson

Now the following error is occurring, I have installed all the packages referring to the Write function, but the ero still persists

Error Message:


R. Script Error
Error: could not find function "Write.table"
Execution stopped

@vitexo87

 

The write.table function is in the utils package and usually is installed by default. Possible you are missing the library(utils) statement before you write the table. I don't know if it is nessecary, but it doesn't hurt to try.

 

Let me know if the error persists.

 

library(stringr) 
library(utils)

# Write.csv (dataset.file = "PowerBIExport.csv")
Write.table (str_trim (dataset), file ="C: /Users/vitor.oliveira/Desktop/teste.txt ", sep =" \ t ", row.names = FALSE)

 

 

@alanhodgson

 

I tried but the same error is still occurring

 

 

I did a test with the direct script in r studio and the error log is the same

@vitexo87

Interesting...

 

Well lets start from the basics. Can you post the output of these 2 commands in RStudio console:

 

- sessionInfo()

- packageversion("utils")

 

This is mine:

 

> sessionInfo()R version 3.3.1 (2016-06-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] readxl_0.1.1        stringr_1.0.0       RevoUtilsMath_8.0.3

loaded via a namespace (and not attached):
[1] magrittr_1.5     RevoUtils_10.0.1 tools_3.3.1      Rcpp_0.12.5      stringi_1.1.1   
> packageVersion("utils")[1] ‘3.3.1’

 

@alanhodgson

When I run the commands:

 

- sessionInfo ()
- packageversion ( "utils")

 

The following log appears:


> - sessionInfo ()
Error in sessionInfo (): invalid argument to unary operator
> - packageversion ( "utils")
Error: could not find function "packageversion"

 

The r studio log when I run the export data script:

 

R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> pkg.env <- new.env()
>
> pkg.env$cur.val <- 0
> pkg.env$times.changed <- 0
>
> inc <- function(by=1) {
+ pkg.env$times.changed <- pkg.env$times.changed + 1
+ pkg.env$cur.val <- pkg.env$cur.val + by
+ pkg.env$cur.val
+ }
>
> dec <- function(by=1) {
+ pkg.env$times.changed <- pkg.env$times.changed + 1
+ pkg.env$cur.val <- pkg.env$cur.val - by
+ pkg.env$cur.val
+ }
>
> cur <- function(){
+ cat('the current value is', pkg.env$cur.val, 'and it has been changed',
+ pkg.env$times.changed, 'times\n')
+ }
>
> inc()
[1] 1
> inc()
[1] 2
> inc(5)
[1] 7
> dec()
[1] 6
> dec(2)
[1] 4
> inc()
[1] 5
> cur()
the current value is 5 and it has been changed 6 times
> library("car", lib.loc="~/R/win-library/3.3")
Warning message:
package ‘car’ was built under R version 3.3.2
> library("chron", lib.loc="~/R/win-library/3.3")
Warning message:
package ‘chron’ was built under R version 3.3.2
> library("colorspace", lib.loc="~/R/win-library/3.3")
> library("data.table", lib.loc="~/R/win-library/3.3")
data.table 1.9.6 For help type ?data.table or https://github.com/Rdatatable/data.table/wiki
The fastest way to learn (by data.table authors): https://www.datacamp.com/courses/data-analysis-the-data-table-way
Warning message:
package ‘data.table’ was built under R version 3.3.2
> library("dichromat", lib.loc="~/R/win-library/3.3")
> library("digest", lib.loc="~/R/win-library/3.3")
> library("ez", lib.loc="~/R/win-library/3.3")
Warning message:
package ‘ez’ was built under R version 3.3.2
> library("forecast", lib.loc="~/R/win-library/3.3")
Carregando pacotes exigidos: zoo

Attaching package: ‘zoo’

The following objects are masked from ‘package:base’:

as.Date, as.Date.numeric

Carregando pacotes exigidos: timeDate
This is forecast 7.1

> library("utils", lib.loc="C:/Program Files/R/R-3.3.1/library")
> library("translations", lib.loc="C:/Program Files/R/R-3.3.1/library")
Error in library("translations", lib.loc = "C:/Program Files/R/R-3.3.1/library") :
package ‘translations’ does not have a namespace and should be re-installed
> library("tools", lib.loc="C:/Program Files/R/R-3.3.1/library")
> library("tcltk", lib.loc="C:/Program Files/R/R-3.3.1/library")
> library("survival", lib.loc="C:/Program Files/R/R-3.3.1/library")
> library("stats4", lib.loc="C:/Program Files/R/R-3.3.1/library")
> library("stats", lib.loc="C:/Program Files/R/R-3.3.1/library")
> library("splines", lib.loc="C:/Program Files/R/R-3.3.1/library")
> library("spatial", lib.loc="C:/Program Files/R/R-3.3.1/library")
> library("rpart", lib.loc="C:/Program Files/R/R-3.3.1/library")
> library("parallel", lib.loc="C:/Program Files/R/R-3.3.1/library")
> library("nlme", lib.loc="C:/Program Files/R/R-3.3.1/library")

Attaching package: ‘nlme’

The following object is masked from ‘package:forecast’:

getResponse

> library("nnet", lib.loc="C:/Program Files/R/R-3.3.1/library")
> library("mgcv", lib.loc="C:/Program Files/R/R-3.3.1/library")
This is mgcv 1.8-12. For overview type 'help("mgcv-package")'.

Attaching package: ‘mgcv’

The following object is masked from ‘package:nnet’:

multinom

> library("methods", lib.loc="C:/Program Files/R/R-3.3.1/library")
> library("lattice", lib.loc="C:/Program Files/R/R-3.3.1/library")
> library("MASS", lib.loc="C:/Program Files/R/R-3.3.1/library")
> library("Matrix", lib.loc="C:/Program Files/R/R-3.3.1/library")
Error in unloadNamespace(package) :
namespace ‘Matrix’ is imported by ‘quantreg’, ‘pbkrtest’, ‘survival’, ‘MatrixModels’, ‘ez’, ‘mgcv’, ‘lme4’ so cannot be unloaded
Error in library("Matrix", lib.loc = "C:/Program Files/R/R-3.3.1/library") :
Package ‘Matrix’ version 1.2.7.1 cannot be unloaded
> library("KernSmooth", lib.loc="C:/Program Files/R/R-3.3.1/library")
KernSmooth 2.23 loaded
Copyright M. P. Wand 1997-2009
> library("grid", lib.loc="C:/Program Files/R/R-3.3.1/library")
> library("grDevices", lib.loc="C:/Program Files/R/R-3.3.1/library")
> library("graphics", lib.loc="C:/Program Files/R/R-3.3.1/library")
> library("foreign", lib.loc="C:/Program Files/R/R-3.3.1/library")
> library("datasets", lib.loc="C:/Program Files/R/R-3.3.1/library")
> library("compiler", lib.loc="C:/Program Files/R/R-3.3.1/library")
> library("codetools", lib.loc="C:/Program Files/R/R-3.3.1/library")
> library("cluster", lib.loc="C:/Program Files/R/R-3.3.1/library")
> library("class", lib.loc="C:/Program Files/R/R-3.3.1/library")
> library("boot", lib.loc="C:/Program Files/R/R-3.3.1/library")

Attaching package: ‘boot’

The following object is masked from ‘package:lattice’:

melanoma

The following object is masked from ‘package:survival’:

aml

The following object is masked from ‘package:car’:

logit

> library("tseries", lib.loc="~/R/win-library/3.3")

‘tseries’ version: 0.10-35

‘tseries’ is a package for time series analysis and computational finance.

See ‘library(help="tseries")’ for details.


Attaching package: ‘tseries’

The following object is masked from ‘package:chron’:

is.weekend

> library("trimTrees", lib.loc="~/R/win-library/3.3")
Carregando pacotes exigidos: randomForest
randomForest 4.6-12
Type rfNews() to see new features/changes/bug fixes.
Carregando pacotes exigidos: mlbench
Warning messages:
1: package ‘trimTrees’ was built under R version 3.3.2
2: package ‘randomForest’ was built under R version 3.3.2
3: package ‘mlbench’ was built under R version 3.3.2
> library("TriMatch", lib.loc="~/R/win-library/3.3")
Carregando pacotes exigidos: ggplot2

Attaching package: ‘ggplot2’

The following object is masked from ‘package:randomForest’:

margin

Carregando pacotes exigidos: scales
Carregando pacotes exigidos: reshape2

Attaching package: ‘reshape2’

The following objects are masked from ‘package:data.table’:

dcast, melt

Warning messages:
1: package ‘TriMatch’ was built under R version 3.3.2
2: package ‘reshape2’ was built under R version 3.3.2
> library("SparseM", lib.loc="~/R/win-library/3.3")

Attaching package: ‘SparseM’

The following object is masked from ‘package:base’:

backsolve

Warning message:
package ‘SparseM’ was built under R version 3.3.2
> library("stringi", lib.loc="~/R/win-library/3.3")
> library("stringr", lib.loc="~/R/win-library/3.3")
> library("RcppEigen", lib.loc="~/R/win-library/3.3")
Warning message:
package ‘RcppEigen’ was built under R version 3.3.2
> library("RcppArmadillo", lib.loc="~/R/win-library/3.3")

Attaching package: ‘RcppArmadillo’

The following objects are masked from ‘package:RcppEigen’:

fastLm, fastLmPure

> library("Rcpp", lib.loc="~/R/win-library/3.3")
> library("RColorBrewer", lib.loc="~/R/win-library/3.3")
> install.packages(";")
Installing package into ‘C:/Users/vitor.oliveira/Documents/R/win-library/3.3’
(as ‘lib’ is unspecified)
Warning in install.packages :
package ‘;’ is not available (for R version 3.3.1)
> install.packages("WrightMap")
Installing package into ‘C:/Users/vitor.oliveira/Documents/R/win-library/3.3’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/WrightMap_1.2.1.zip'
Content type 'application/zip' length 140621 bytes (137 KB)
downloaded 137 KB

package ‘WrightMap’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
C:\Users\vitor.oliveira\AppData\Local\Temp\RtmpIFPl6C\downloaded_packages

Restarting R session...

> install.packages("tables")
Installing package into ‘C:/Users/vitor.oliveira/Documents/R/win-library/3.3’
(as ‘lib’ is unspecified)
also installing the dependencies ‘mime’, ‘evaluate’, ‘highr’, ‘markdown’, ‘yaml’, ‘knitr’, ‘survival’, ‘Formula’, ‘latticeExtra’, ‘acepack’, ‘htmlTable’, ‘viridis’, ‘htmltools’, ‘Hmisc’

trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/mime_0.5.zip'
Content type 'application/zip' length 37483 bytes (36 KB)
downloaded 36 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/evaluate_0.10.zip'
Content type 'application/zip' length 47707 bytes (46 KB)
downloaded 46 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/highr_0.6.zip'
Content type 'application/zip' length 35881 bytes (35 KB)
downloaded 35 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/markdown_0.7.7.zip'
Content type 'application/zip' length 164966 bytes (161 KB)
downloaded 161 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/yaml_2.1.14.zip'
Content type 'application/zip' length 175880 bytes (171 KB)
downloaded 171 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/knitr_1.15.1.zip'
Content type 'application/zip' length 1004547 bytes (981 KB)
downloaded 981 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/survival_2.40-1.zip'
Content type 'application/zip' length 5109270 bytes (4.9 MB)
downloaded 4.9 MB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/Formula_1.2-1.zip'
Content type 'application/zip' length 163536 bytes (159 KB)
downloaded 159 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/latticeExtra_0.6-28.zip'
Content type 'application/zip' length 2069259 bytes (2.0 MB)
downloaded 2.0 MB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/acepack_1.4.1.zip'
Content type 'application/zip' length 90511 bytes (88 KB)
downloaded 88 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/htmlTable_1.7.zip'
Content type 'application/zip' length 173147 bytes (169 KB)
downloaded 169 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/viridis_0.3.4.zip'
Content type 'application/zip' length 1746372 bytes (1.7 MB)
downloaded 1.7 MB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/htmltools_0.3.5.zip'
Content type 'application/zip' length 578621 bytes (565 KB)
downloaded 565 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/Hmisc_4.0-0.zip'
Content type 'application/zip' length 1769236 bytes (1.7 MB)
downloaded 1.7 MB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/tables_0.7.92.zip'
Content type 'application/zip' length 396375 bytes (387 KB)
downloaded 387 KB

package ‘mime’ successfully unpacked and MD5 sums checked
package ‘evaluate’ successfully unpacked and MD5 sums checked
package ‘highr’ successfully unpacked and MD5 sums checked
package ‘markdown’ successfully unpacked and MD5 sums checked
package ‘yaml’ successfully unpacked and MD5 sums checked
package ‘knitr’ successfully unpacked and MD5 sums checked
package ‘survival’ successfully unpacked and MD5 sums checked
package ‘Formula’ successfully unpacked and MD5 sums checked
package ‘latticeExtra’ successfully unpacked and MD5 sums checked
package ‘acepack’ successfully unpacked and MD5 sums checked
package ‘htmlTable’ successfully unpacked and MD5 sums checked
package ‘viridis’ successfully unpacked and MD5 sums checked
package ‘htmltools’ successfully unpacked and MD5 sums checked
package ‘Hmisc’ successfully unpacked and MD5 sums checked
package ‘tables’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
C:\Users\vitor.oliveira\AppData\Local\Temp\Rtmp6xPAnB\downloaded_packages
> install.packages("utility")
Installing package into ‘C:/Users/vitor.oliveira/Documents/R/win-library/3.3’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/utility_1.3.zip'
Content type 'application/zip' length 312637 bytes (305 KB)
downloaded 305 KB

package ‘utility’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
C:\Users\vitor.oliveira\AppData\Local\Temp\Rtmp6xPAnB\downloaded_packages
> install.packages("utiml")
Installing package into ‘C:/Users/vitor.oliveira/Documents/R/win-library/3.3’
(as ‘lib’ is unspecified)
also installing the dependencies ‘httpuv’, ‘jsonlite’, ‘xtable’, ‘R6’, ‘sourcetools’, ‘GlobalOptions’, ‘shape’, ‘shiny’, ‘XML’, ‘circlize’, ‘mldr’

trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/httpuv_1.3.3.zip'
Content type 'application/zip' length 898869 bytes (877 KB)
downloaded 877 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/jsonlite_1.1.zip'
Content type 'application/zip' length 1149950 bytes (1.1 MB)
downloaded 1.1 MB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/xtable_1.8-2.zip'
Content type 'application/zip' length 710021 bytes (693 KB)
downloaded 693 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/R6_2.2.0.zip'
Content type 'application/zip' length 197099 bytes (192 KB)
downloaded 192 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/sourcetools_0.1.5.zip'
Content type 'application/zip' length 526050 bytes (513 KB)
downloaded 513 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/GlobalOptions_0.0.10.zip'
Content type 'application/zip' length 71455 bytes (69 KB)
downloaded 69 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/shape_1.4.2.zip'
Content type 'application/zip' length 755291 bytes (737 KB)
downloaded 737 KB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/shiny_0.14.2.zip'
Content type 'application/zip' length 2659168 bytes (2.5 MB)
downloaded 2.5 MB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/XML_3.98-1.5.zip'
Content type 'application/zip' length 4291889 bytes (4.1 MB)
downloaded 4.1 MB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/circlize_0.3.9.zip'
Content type 'application/zip' length 3858762 bytes (3.7 MB)
downloaded 3.7 MB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/mldr_0.3.22.zip'
Content type 'application/zip' length 1315233 bytes (1.3 MB)
downloaded 1.3 MB

trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/utiml_0.1.1.zip'
Content type 'application/zip' length 522131 bytes (509 KB)
downloaded 509 KB

package ‘httpuv’ successfully unpacked and MD5 sums checked
package ‘jsonlite’ successfully unpacked and MD5 sums checked
package ‘xtable’ successfully unpacked and MD5 sums checked
package ‘R6’ successfully unpacked and MD5 sums checked
package ‘sourcetools’ successfully unpacked and MD5 sums checked
package ‘GlobalOptions’ successfully unpacked and MD5 sums checked
package ‘shape’ successfully unpacked and MD5 sums checked
package ‘shiny’ successfully unpacked and MD5 sums checked
package ‘XML’ successfully unpacked and MD5 sums checked
package ‘circlize’ successfully unpacked and MD5 sums checked
package ‘mldr’ successfully unpacked and MD5 sums checked
package ‘utiml’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
C:\Users\vitor.oliveira\AppData\Local\Temp\Rtmp6xPAnB\downloaded_packages
> Write.table (str_trim (dataset), file ="C: /Users/vitor.oliveira/Desktop/teste.txt ", sep =" \ t ", row.names = FALSE)
Error: could not find function "Write.table"
> - packageversion("utils")
Error: could not find function "packageversion"
>
>
> - sessionInfo()
Error in -sessionInfo() : invalid argument to unary operator
> - packageversion("utils")
Error: could not find function "packageversion"
>

Obs: Before I had done the installation of the two packages that you quoted.

Hey @vitexo87

 

Might have something to do with the warning messages after some of the package installations.

 

Look like you're getting the warnings because a few of the packages you need were built using an R version that is newer than the R version you are running. This can potentially be a problem, though it's likely not a problem, hence it's just a warning. If any of those packages have a different behaviour in the newer R version, this would be critical, though that's likely not the case.

 

I suggest installing the newest version of R 3.3.2 and see if that fixes the problem.

https://www.r-project.org/

@alanhodgson

I updated the version and still the same error persists:

 

Error: could not find function "Write.table"

Well @vitexo87,

 

I'm out of ideas. Hopefully someone can provide some more information on this error.

 

Good luck! 

 

 

 

@alanhodgson

 

Thanks for the help, the problem is the microsoft create a BI tool in full year 2016 where it is not possible to export the data from a simple report to excel without the user having to learn a new programming language for this, New software and unable to meet any technical call that is open with them, if decoding killed would never have migrated from a qlikview BI to that extremely limited tool that is microsoft power bi.

Anonymous
Not applicable

The advice from @alanhodgson with stringr and str_trim worked for me.  Note that R is case-sensitive - write.table will work but Write.table will generate "Error: could not find function Write.table".

 

You could also trim the text in Power Query before you export with R, so the following code works for me:

write.table (dataset, file ="D:/teste.txt", sep ="\t", row.names = FALSE)

Depending on your requirements, Power Query is available in Excel - could you transform and save your data there if Power BI is not suitable for you?

@Anonymous

Now the following error is occurring:

Error in is.data.frame (x): object 'dataset' not found

Anonymous
Not applicable

Can you post the full query text (from Advanced Editor) so we can see exactly what the issue might be?

@Anonymous

Script:
# Write.csv (dataset.file = "PowerBIExport.csv")
write.table (dataset, file ="C: /Users/vitor.oliveira/Desktop/teste.txt ", sep ="\t", row.names = FALSE)

 

Error Log Power BI:
Error Message:
R. Script Error
Error in file (file, ifelse (append, "a", "w")):
   Can not open connection
Calls: write.table -> file
In addition: Warning message:
In file (file, ifelse (append, "a", "w")):
   Could not open file 'C: /Users/vitor.oliveira/Desktop/teste.txt': No such file or directory
Execution stopped

 

Error Log R Studio:

# Write.csv (dataset.file = "PowerBIExport.csv")
> Write.table (dataset, file = "C: /Users/vitor.oliveira/Desktop/teste.txt", sep = "\ t", row.names = FALSE)
Error in is.data.frame (x): object 'dataset' not found
# Write.csv (dataset.file = "PowerBIExport.csv")

Hey @vitexo87 and @Anonymous,

 

After a bunch of testing, this worked for me:

 

write.table (dataset, file = 'C: /Users/vitor.oliveira/Desktop/teste.txt', sep ='\t', row.names = FALSE)

 

 I think you just had some syntax errors in your script. If this doesn't work and you get the same error, make sure the file location you are writing to is not read only (saw a few warnings about this while I was testing).

 

Alan

@alanhodgson and @Anonymous

 

I changed the script and the error continues to occur, I already did the test in other directories with read and write permission and the error is the same

Anonymous
Not applicable

@vitexo87,

Just to be clear, that one line of R script (write.table...) is giving you two different errors:

  1. In Power BI, you get "Could not open file 'C: /Users/vitor.oliveira/Desktop/teste.txt': No such file or directory"; and
  2. In R Studio, you get "Error in is.data.frame (x): object 'dataset' not found"?

Is that right?

 

Are you calling the R script from a Power Query, or from an R visual (your R script works fine for me in both)?

 

What is the data set you are exporting, and how are you referencing it?

@Anonymous and @alanhodgson

The goal is to run in power bi to export data from a table-type report to a file and then to use it in an excel, I'm having to do this because in this report I have some time money clusters with 2 decimal places and when I try to export Via .csv many special characters are displayed

Anonymous
Not applicable

@vitexo87,

I think the R script can exprt as you need, but to get to teh bottom of the errors you're getting, can you advise on the questions I asjed earlier:

Just to be clear, that one line of R script (write.table...) is giving you two different errors:

  1. In Power BI, you get "Could not open file 'C: /Users/vitor.oliveira/Desktop/teste.txt': No such file or directory"; and
  2. In R Studio, you get "Error in is.data.frame (x): object 'dataset' not found"?

Is that right?

 

Are you calling the R script from a Power Query, or from an R visual (your R script works fine for me in both)?

 

For the data set you are exporting, and how are you referencing it in Power BI/R exactly?

Anonymous
Not applicable

@Anonymous 

I am trying to export data from power bi to csv file using R

I am giving the below commandin Power Query

write.csv(ALL_Data, "C:\\Users\\username\\Documents\\folder 1\\folder 2\\folder 3\\folder 4\\filename.csv")

I am getting the below error please help

DataSource.Error: ADO.NET: R script error.
Error in is.data.frame(x) : object 'ALL_Data' not found
Calls: write.csv ... eval.parent -> eval -> eval -> write.table -> is.data.frame
Execution halted

Details:
    DataSourceKind=R
    DataSourcePath=R
    Message=R script error.
Error in is.data.frame(x) : object 'ALL_Data' not found
Calls: write.csv ... eval.parent -> eval -> eval -> write.table -> is.data.frame

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.