Forum Discussion
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
- alanhodgson
Solution Supplier
Hey Anonymous,
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
- AnonymousNot applicable
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- alanhodgson
Solution Supplier
Anonymous
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)