Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading range out of bounds #109

Open
jherculecitepa opened this issue Jun 15, 2023 · 1 comment
Open

Reading range out of bounds #109

jherculecitepa opened this issue Jun 15, 2023 · 1 comment

Comments

@jherculecitepa
Copy link

Hello,

Since merged cells are not parsed properly my column headers are not in line with my data. I devised a work-around but I need to read a specific range of values in my .ods file. Howerver, since merged cells values are pushed to the left end column, when I specify a range I get an error that column is undefined. Below a reprex. I am expecting to get expected_df as the result of read_ods and not an error.

Thanks for your help.

Jonathan

library(tibble)
#> Warning: le package 'tibble' a été compilé avec la version R 4.2.3
library(readODS)
df <- tibble(col1 = c(1,2), 
            col2 = c(3,4))
            
df
#> # A tibble: 2 × 2
#>    col1  col2
#>   <dbl> <dbl>
#> 1     1     3
#> 2     2     4

write_ods(x = df, path = "x.ods")
read_ods(path = "x.ods", range = "A1:C2")
#> Error in `[.data.frame`(raw_sheet, range_select$ul[1]:range_select$lr[1], : colonnes non définies sélectionnées

expected_df <- tibble(col1 = c(1,2), 
                      col2 = c(3,4), 
                      C = c(NA_character_,NA_character_))
                              
expected_df
#> # A tibble: 2 × 3
#>    col1  col2 C    
#>   <dbl> <dbl> <chr>
#> 1     1     3 <NA> 
#> 2     2     4 <NA>

Created on 2023-06-15 with reprex v2.0.2

@chainsawriot
Copy link
Collaborator

@jherculecitepa As it is the behaviour of readxl, we should keep this in our agenda. But sorry that we have no ETA. If you can, you might also take a look on how to implement this.

df <- tibble::tibble(col1 = c(1,2), 
                     col2 = c(3,4))
xlsx_file <- writexl::write_xlsx(df)
readxl::read_xlsx(path = xlsx_file, range = "A1:C3")
#> New names:
#> • `` -> `...3`
#> # A tibble: 2 × 3
#>    col1  col2 ...3 
#>   <dbl> <dbl> <lgl>
#> 1     1     3 NA   
#> 2     2     4 NA

df <- tibble::tibble(col1 = c(1,2), 
                     col2 = c(3,4))
ods_file <- readODS::write_ods(df)
readODS::read_ods(path = ods_file, range = "A1:C3")
#> # A tibble: 2 × 2
#>    col1  col2
#>   <dbl> <dbl>
#> 1     1     3
#> 2     2     4

Created on 2023-08-21 with reprex v2.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants