Readxl error message with default example

readxl

#1

Dear gurus,
Yesterday I experienced an error while reading any Excel file with read_excel() function.
I checked the example from help system and error is still there.

library(readxl)
datasets <- readxl_example(“datasets.xlsx”)
read_excel(datasets)
Error: Can’t convert a string to a character vector

Has anybody had such an error (under Windows 7 OS)? And what that can mean?

My session info:

sessionInfo()
R version 3.4.3 (2017-11-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
Matrix products: default
locale:
[1] LC_COLLATE=Russian_Russia.1251 LC_CTYPE=Russian_Russia.1251
[3] LC_MONETARY=Russian_Russia.1251 LC_NUMERIC=C
[5] LC_TIME=Russian_Russia.1251
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] readxl_1.0.0

While doing debug() I have following:

read_excel(datasets)
debugging in: read_excel(datasets)
debug: {
read_excel_(path = path, sheet = sheet, range = range, col_names = col_names,
col_types = col_types, na = na, trim_ws = trim_ws, skip = skip,
n_max = n_max, guess_max = guess_max, excel_format(path))
}
Browse[2]> s
debug: read_excel_(path = path, sheet = sheet, range = range, col_names = col_names,
col_types = col_types, na = na, trim_ws = trim_ws, skip = skip,
n_max = n_max, guess_max = guess_max, excel_format(path))
Browse[2]> s
debugging in: read_excel_(path = path, sheet = sheet, range = range, col_names = col_names,
col_types = col_types, na = na, trim_ws = trim_ws, skip = skip,
n_max = n_max, guess_max = guess_max, excel_format(path))
debug: {
if (format == “xls”) {
sheets_fun <- xls_sheets
read_fun <- read_xls_
}
else {
sheets_fun <- xlsx_sheets
read_fun <- read_xlsx_
}
sheet <- standardise_sheet(sheet, range, sheets_fun(path))
shim <- !is.null(range)
limits <- standardise_limits(range, skip, n_max, has_col_names = isTRUE(col_names))
col_types <- check_col_types(col_types)
guess_max <- check_guess_max(guess_max)
trim_ws <- check_bool(trim_ws, “trim_ws”)
tibble::repair_names(tibble::as_tibble(read_fun(path = path,
sheet = sheet, limits = limits, shim = shim, col_names = col_names,
col_types = col_types, na = na, trim_ws = trim_ws, guess_max = guess_max),
validate = FALSE), prefix = “X”, sep = “")
}
Browse[3]> n
debug: if (format == “xls”) {
sheets_fun <- xls_sheets
read_fun <- read_xls_
} else {
sheets_fun <- xlsx_sheets
read_fun <- read_xlsx_
}
Browse[3]> n
debug: sheets_fun <- xlsx_sheets
Browse[3]> n
debug: read_fun <- read_xlsx_
Browse[3]> n
debug: sheet <- standardise_sheet(sheet, range, sheets_fun(path))
Browse[3]> n
debug: shim <- !is.null(range)
Browse[3]> n
debug: limits <- standardise_limits(range, skip, n_max, has_col_names = isTRUE(col_names))
Browse[3]> n
debug: col_types <- check_col_types(col_types)
Browse[3]> n
debug: guess_max <- check_guess_max(guess_max)
Browse[3]> n
debug: trim_ws <- check_bool(trim_ws, “trim_ws”)
Browse[3]> n
debug: tibble::repair_names(tibble::as_tibble(read_fun(path = path,
sheet = sheet, limits = limits, shim = shim, col_names = col_names,
col_types = col_types, na = na, trim_ws = trim_ws, guess_max = guess_max),
validate = FALSE), prefix = “X”, sep = "
”)
Browse[3]> s
debugging in: tibble::repair_names
debug: {
pkg <- as.character(substitute(pkg))
name <- as.character(substitute(name))
getExportedValue(pkg, name)
}
Browse[4]> n
debug: pkg <- as.character(substitute(pkg))
Browse[4]> n
debug: name <- as.character(substitute(name))
Browse[4]> n
debug: getExportedValue(pkg, name)
Browse[4]> s
debugging in: getExportedValue(pkg, name)
debug: {
ns <- asNamespace(ns)
if (isBaseNamespace(ns))
get(name, envir = ns, inherits = FALSE)
else {
if (!is.null(oNam <- .getNamespaceInfo(ns, “exports”)[[name]])) {
get0(oNam, envir = ns)
}
else {
ld <- .getNamespaceInfo(ns, “lazydata”)
if (!is.null(obj <- ld[[name]]))
obj
else {
if (exists(name, envir = ld, inherits = FALSE))
NULL
else stop(gettextf("’%s’ is not an exported object from ‘namespace:%s’",
name, getNamespaceName(ns)), call. = FALSE,
domain = NA)
}
}
}
}
Browse[5]> n
debug: ns <- asNamespace(ns)
Browse[5]> n
debug: if (isBaseNamespace(ns)) get(name, envir = ns, inherits = FALSE) else {
if (!is.null(oNam <- .getNamespaceInfo(ns, “exports”)[[name]])) {
get0(oNam, envir = ns)
}
else {
ld <- .getNamespaceInfo(ns, “lazydata”)
if (!is.null(obj <- ld[[name]]))
obj
else {
if (exists(name, envir = ld, inherits = FALSE))
NULL
else stop(gettextf("’%s’ is not an exported object from ‘namespace:%s’",
name, getNamespaceName(ns)), call. = FALSE, domain = NA)
}
}
}
Browse[5]> n
debug: if (!is.null(oNam <- .getNamespaceInfo(ns, “exports”)[[name]])) {
get0(oNam, envir = ns)
} else {
ld <- .getNamespaceInfo(ns, “lazydata”)
if (!is.null(obj <- ld[[name]]))
obj
else {
if (exists(name, envir = ld, inherits = FALSE))
NULL
else stop(gettextf("’%s’ is not an exported object from ‘namespace:%s’",
name, getNamespaceName(ns)), call. = FALSE, domain = NA)
}
}
Browse[5]> n
debug: get0(oNam, envir = ns)
Browse[5]> n
exiting from: getExportedValue(pkg, name)
exiting from: tibble::repair_names
exiting from: read_excel_(path = path, sheet = sheet, range = range, col_names = col_names,
col_types = col_types, na = na, trim_ws = trim_ws, skip = skip,
n_max = n_max, guess_max = guess_max, excel_format(path))
exiting from: read_excel(datasets)

Error: Can’t convert a string to a character vector


#2

Hi @mig,

For future reference, it’s much easier to read and for others to run the code if you can turn it into a self-contained reprex (short for minimal reproducible example). You’re close here, but, since it’s not formatted as code, things like curly quotes
end up causing just a bit of extra work for anyone testing your code.

If you’ve never heard of a reprex before, you might want to start by reading the tidyverse.org help page. The reprex dos and don’ts are also useful.

As for this example, I’m not able to replicate the issue (see reprex below), but I’m on a Mac. Have you tried using the dev version from GitHub?

library(readxl)
datasets <- readxl_example("datasets.xlsx")
read_excel(datasets)
#> # A tibble: 150 x 5
#>    Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#>           <dbl>       <dbl>        <dbl>       <dbl> <chr>  
#>  1         5.10        3.50         1.40       0.200 setosa 
#>  2         4.90        3.00         1.40       0.200 setosa 
#>  3         4.70        3.20         1.30       0.200 setosa 
#>  4         4.60        3.10         1.50       0.200 setosa 
#>  5         5.00        3.60         1.40       0.200 setosa 
#>  6         5.40        3.90         1.70       0.400 setosa 
#>  7         4.60        3.40         1.40       0.300 setosa 
#>  8         5.00        3.40         1.50       0.200 setosa 
#>  9         4.40        2.90         1.40       0.200 setosa 
#> 10         4.90        3.10         1.50       0.100 setosa 
#> # ... with 140 more rows

Created on 2018-01-22 by the reprex package (v0.1.1.9000).


#3

I am on a mac and cannot reproduce the error. I’ll look over the debug stream you showed and see if I can devine what issue you are looking into.

I also tried this on a WIndows 10 system and got the same results

Here is a reprex for my test:

library(readxl)
datasets <- readxl_example("datasets.xlsx")
read_excel(datasets)
#> # A tibble: 150 x 5
#>    Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#>           <dbl>       <dbl>        <dbl>       <dbl> <chr>  
#>  1         5.10        3.50         1.40       0.200 setosa 
#>  2         4.90        3.00         1.40       0.200 setosa 
#>  3         4.70        3.20         1.30       0.200 setosa 
#>  4         4.60        3.10         1.50       0.200 setosa 
#>  5         5.00        3.60         1.40       0.200 setosa 
#>  6         5.40        3.90         1.70       0.400 setosa 
#>  7         4.60        3.40         1.40       0.300 setosa 
#>  8         5.00        3.40         1.50       0.200 setosa 
#>  9         4.40        2.90         1.40       0.200 setosa 
#> 10         4.90        3.10         1.50       0.100 setosa 
#> # ... with 140 more rows

#4

This is just a guess as to what is wrong. The file you are opening It is actually a .zip file. There are 4 worksheets in it. Maybe somehow on your machine that file may have been corrupted.

The path on my machine is “/Library/Frameworks/R.framework/Versions/3.4/Resources/library/readxl/extdata/datasets.xlsx” but I’m sure on yours it is quite different, but that is what is stored in datasets.

But in any case do you have a copy of excel on your machine? If not you can download a free readonly viewer from

https://www.microsoft.com/en-us/download/details.aspx?id=10

See if excel can open the file. If it can’t then the files are somehow corrupted or for whatever reason you don’t have access rights to it… though that would be strange.

So please try opening the file directly with excel and let us know what happens.


#5

Thank you @mara for good point.
I checked the dev version, but the same example ends up with a different error below.

library(readxl)
datasets <- readxl_example("datasets.xlsx")
read_excel(datasets)
#> Error in read_fun(path = path, sheet_i = sheet, limits = limits, shim = shim,  : 
  object '_readxl_read_xlsx_' not found

A traceback shows the following:

5: read_fun(path = path, sheet_i = sheet, limits = limits, shim = shim,
col_names = col_names, col_types = col_types, na = na, trim_ws = trim_ws,
guess_max = guess_max)
4: tibble::as_tibble(read_fun(path = path, sheet_i = sheet, limits = limits,
shim = shim, col_names = col_names, col_types = col_types,
na = na, trim_ws = trim_ws, guess_max = guess_max), validate = FALSE)
3: tibble::repair_names(tibble::as_tibble(read_fun(path = path,
sheet_i = sheet, limits = limits, shim = shim, col_names = col_names,
col_types = col_types, na = na, trim_ws = trim_ws, guess_max = guess_max),
validate = FALSE), prefix = “X”, sep = “__”)
2: read_excel_(path = path, sheet = sheet, range = range, col_names = col_names,
col_types = col_types, na = na, trim_ws = trim_ws, skip = skip,
n_max = n_max, guess_max = guess_max, format = format)
1: read_excel(xlsx_example)

Thanks everyone replied. Linux / Mac versions do not produce an issue as I see. My case is Windows 7 only. An example xlsx file (as well as any other spreadsheet file) can be opened by MS Excel 2016 without any problem.


#6

Can I see full devtools::session_info() on the Windows 7 machine?


#7

Yes, the output below.

devtools::session_info()
Session info -----------------------------------------------------------------------------
setting value
version R version 3.4.3 (2017-11-30)
system x86_64, mingw32
ui RStudio (1.1.383)
language (EN)
collate Russian_Russia.1251
tz Europe/Moscow
date 2018-01-23
Packages ---------------------------------------------------------------------------------
package * version date source
assertthat 0.2.0 2017-04-11 CRAN (R 3.4.0)
backports 1.1.2 2017-12-13 CRAN (R 3.4.3)
base * 3.4.3 2017-12-06 local
callr 1.0.0.9000 2017-05-10 Github (r-pkgs/callr@927db5a)
cellranger 1.1.0 2016-07-27 CRAN (R 3.4.0)
clipr 0.4.0 2017-11-03 CRAN (R 3.4.2)
colorspace 1.3-2 2016-12-14 CRAN (R 3.4.0)
compiler 3.4.3 2017-12-06 local
crayon 1.3.4 2017-09-16 CRAN (R 3.4.1)
datasets * 3.4.3 2017-12-06 local
debugme 1.1.0 2017-10-22 CRAN (R 3.4.2)
devtools 1.13.4 2017-11-09 CRAN (R 3.4.2)
digest 0.6.14 2018-01-14 CRAN (R 3.4.3)
evaluate 0.10.1 2017-06-24 CRAN (R 3.4.0)
formatR 1.5 2017-04-25 CRAN (R 3.4.0)
ggplot2 2.2.1.9000 2017-06-29 Github (hadley/ggplot2@04a707e)
graphics * 3.4.3 2017-12-06 local
grDevices * 3.4.3 2017-12-06 local
grid 3.4.3 2017-12-06 local
gtable 0.2.0 2016-02-26 CRAN (R 3.4.0)
htmltools 0.3.6 2017-04-28 CRAN (R 3.4.0)
knitr 1.18 2017-12-27 CRAN (R 3.4.3)
lazyeval 0.2.1 2017-10-29 CRAN (R 3.4.2)
magrittr 1.5 2014-11-22 CRAN (R 3.4.0)
memoise 1.1.0 2017-04-21 CRAN (R 3.4.0)
methods * 3.4.3 2017-12-06 local
munsell 0.4.3 2016-02-13 CRAN (R 3.4.0)
pillar 1.1.0 2018-01-14 CRAN (R 3.4.3)
plyr 1.8.4 2016-06-08 CRAN (R 3.4.0)
processx 2.0.0.1 2017-07-30 CRAN (R 3.4.1)
R6 2.2.2 2017-06-17 CRAN (R 3.4.0)
Rcpp 0.12.15 2018-01-20 CRAN (R 3.4.3)
readxl * 1.0.0.9000 2018-01-23 Github (tidyverse/readxl@ed499fb)
reprex * 0.1.1 2017-01-13 CRAN (R 3.4.3)
rlang 0.1.9000 2017-05-10 Github (hadley/rlang@7433d55)
rmarkdown 1.8 2017-11-17 CRAN (R 3.4.3)
rprojroot 1.3-2 2018-01-03 CRAN (R 3.4.3)
rstudioapi 0.7 2017-09-07 CRAN (R 3.4.1)
scales 0.5.0 2017-08-24 CRAN (R 3.4.1)
stats * 3.4.3 2017-12-06 local
stringi 1.1.6 2017-11-17 CRAN (R 3.4.2)
stringr 1.2.0 2017-02-18 CRAN (R 3.4.0)
tibble 1.4.2 2018-01-22 CRAN (R 3.4.3)
tools 3.4.3 2017-12-06 local
utils * 3.4.3 2017-12-06 local
whisker 0.3-2 2013-04-28 CRAN (R 3.4.0)
withr 2.1.1 2017-12-19 CRAN (R 3.4.3)
yaml 2.1.16 2017-12-12 CRAN (R 3.4.3)


#8

So Windows binaries aren’t available yet for tibble 1.4.2 and yet that is your version. I assume you built it (and, at this point, also readxl, from GitHub)? Do you have plenty of other evidence that all is well with your toolchain for building R packages from source with compiled code? I notice that the error you’re getting may have originated with tibble the first time and then, after installing/building dev readxl, it appears to be coming from readxl itself.


#9

The problem may be with the quote symbols (""), which can get changed when copy/pasting them between applications.

Try retyping them manually.


#10

I suppose printing datasets to screen before the read_excel() call would rule out some funny business with paths and quotes, yes.


#11

Thank you very much, @jennybryan
Indeed, the root of the original problem was in tibble 1.4.2.
I removed it, and re-installed 1.4.1 from binaries and that solved issue.

The latter error I mentioned is from dev readxl version, yes. Although it was built from the source without any error with Rtools 3.4 x64.


#12

Glad you are back in business!


#13

Also, I note tibble 1.4.2 binaries are now available for your system. It would be interesting to know if re-installing current CRAN tibble keeps you in a functional state.


#14

Yes, it does with update now


#15

Great! So I think you should be a bit suspicious that your system is really configured properly to build R packages with compiled code. Or else it was an unlucky interaction with tibble specifically. But that is still troubling.