Forum Discussion
R script error when exporting data
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
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)
- Anonymous9 years agoNot applicable
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
- alanhodgson9 years ago
Solution Supplier
Anonymous
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’
- Anonymous9 years agoNot applicable
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.