error when importing . ODS in R

Asked

Viewed 133 times

1

I’m trying to import a table. ods in R

library(readODS)
setwd("~/Documents/Mestrado/dissertacao")
dados <- read_ods("teste.ods", col_names = T)

however when loading the worksheet it does not identify the first row as column name and load the data as character. I tried to convert to matrix and to data frame but still has the same error.

1 answer

1

To read ". ods" files just use the function read_ods package readODS.

In the example below I create an ODS file with the data from mtcars and then I read it.

tf <- tempfile(fileext = ".ods")
readODS::write_ods(mtcars, tf)

mtcars2 <- readODS::read_ods(tf)
#> Parsed with column specification:
#> cols(
#>   mpg = col_double(),
#>   cyl = col_double(),
#>   disp = col_double(),
#>   hp = col_double(),
#>   drat = col_double(),
#>   wt = col_double(),
#>   qsec = col_double(),
#>   vs = col_double(),
#>   am = col_double(),
#>   gear = col_double(),
#>   carb = col_double()
#> )

Note that the information read is identical to the information saved.

head(mtcars2)
#>    mpg cyl disp  hp drat    wt  qsec vs am gear carb
#> 1 21.0   6  160 110 3.90 2.620 16.46  0  1    4    4
#> 2 21.0   6  160 110 3.90 2.875 17.02  0  1    4    4
#> 3 22.8   4  108  93 3.85 2.320 18.61  1  1    4    1
#> 4 21.4   6  258 110 3.08 3.215 19.44  1  0    3    1
#> 5 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2
#> 6 18.1   6  225 105 2.76 3.460 20.22  1  0    3    1

Created on 2019-05-03 by the reprex package (v0.2.1)

It is worth noting that the argument col_names = TRUE is the standard argument and therefore does not need to be provided.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.