1

I am reading an Excel file into R using the read_xlsx function from the readxl package. Some of the columns could be "numerics" in Excel, but I convert everything to a character as I read things in. This solves a lot of downstream problems for me because really none of the data from Excel is actually numeric in practice. Things that look like numerics are really identification numbers of some sort.

Here is my issue. I am trying to read in the following data:

enter image description here

You can see that the first column is a numeric in Excel. When I read this in, I get:

library(readxl)
xl <- read_xlsx("C:/test/test.xlsx", col_types = c("text"))
xl
#> # A tibble: 1 x 3
#>   some_id_number     some_name some_other_name  
#>   <chr>              <chr>     <chr>            
#> 1 310.16000000000003 name      name_Descriptions

Where is that trailing 3 coming from? I have tried to adjust the digits option per this question without any luck.

Any thoughts?

Nick Criswell
  • 1,733
  • 2
  • 16
  • 32
  • When I do that, I see: `structure(list(some_id_number = 310.16, some_name = "name", some_other_name = "name_Descriptions"), row.names = c(NA, -1L), class = c("tbl_df", "tbl", "data.frame"))` So it does show as the decimal. – Nick Criswell Sep 29 '20 at 23:27
  • @TTS I think this question has been answered. It should either be closed as a typo, or TTS should write up an answer and Nick should checkmark it as accepted. – IRTFM Sep 30 '20 at 00:21
  • 1
    I am not sure that this has been answered. The purpose of using `col_types = c('text')` is to avoid issues with the `read_xlsx` function guessing at column types and getting it wrong. All of the columns in the data are text. – Nick Criswell Sep 30 '20 at 00:25
  • 1
    [I found this link](https://github.com/tidyverse/readxl/issues/525) which seems to indicate that this might not be possible and the solution might be to read it all in as text and then try some regex solution that looks for an implausible number of zeros followed by a numeric. – Nick Criswell Sep 30 '20 at 00:27

0 Answers0