Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
9 years ago

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's avatar
    alanhodgson
    Icon for Solution Supplier rankSolution 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

     

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      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

      • alanhodgson's avatar
        alanhodgson
        Icon for Solution Supplier rankSolution 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)