-
Notifications
You must be signed in to change notification settings - Fork 11
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
Improve dims #796
Comments
My 2 cents: I think I specifically disallowed this when I wrote it to avoid unexpected things. I think that keeping a length 1 would be good, (and create less surprise), but maybe I am wrong. Do you think all functions can handle dims as "A1;B3"? library(openxlsx2)
# Last version
packageVersion("openxlsx2")
#> [1] '1.0.0.9000'
wb_dims(x = mtcars, cols = "vs")
#> [1] "H2:H33"
wb_dims(x = mtcars, cols = "am")
#> [1] "I2:I33"
wb_dims(x = mtcars, cols = "cyl")
#> [1] "B2:B33"
# H2:I33
wb_dims(x = mtcars, cols = c("vs", "am"))
#> Error in wb_dims(x = mtcars, cols = c("vs", "am")): Supplying multiple column names is not supported by the `wb_dims()` helper, use the `cols` with a range instead of `x` column names.
#> Use a single `cols` at a time with `wb_dims()`
# B1:B33;I1:I33
wb_dims(x = mtcars, cols = c("cyl", "am"), select = "x")
#> Error in wb_dims(x = mtcars, cols = c("cyl", "am"), select = "x"): Supplying multiple column names is not supported by the `wb_dims()` helper, use the `cols` with a range instead of `x` column names.
#> Use a single `cols` at a time with `wb_dims()` Created on 2023-09-27 with reprex v2.0.2 Other suggestions in #990 (comment) |
Yes I do. But to make it work consistently, some development and lots of testing has to be done. After all there is a reason why it doesn't work right now |
I was thinking about a data validation book chapter and was wondering if it makes sense to add sheet names to Draft: wb$dims(sheet = "MySheet", x = mtcars)
#> MySheet!A1:K33
wb$dims(sheet = "My Sheet", x = mtcars)
#> 'My Sheet'!A1:K33 If we grep for The following functions would be identical: wb$to_df(dims = wb$dims(sheet = "Sheet2", x = matrix(1, 2, 2), col_names = FALSE)
wb$to_df(dims = "Sheet2!A1:B2")
wb_to_df(wb, sheet = "Sheet2", dims = wb_dims(wb = wb, x = matrix(1, 2, 2), col_names = FALSE)
wb_to_df(wb, sheet = "Sheet2", dims = "A1:B2") The data validation example would become something like this: # data validation example
wb <- wb_workbook()$
add_worksheet("Sheet 1")$
add_worksheet("Sheet 2")$
add_data_table(sheet = 1, x = iris[1:30, ])$
add_data(sheet = 2, x = sample(iris$Sepal.Length, 10))
# with wb_dims draft
wb$add_data_validation(
dims = wb$dims(sheet = 1, x = iris[1:30, ], cols = 1),
type = "list",
# "'Sheet 2'!$A$1:$A$10"
value = wb$dims(sheet = 2, cols = 1, rows = seq_len(10))
) |
Further It should be possible to select every row/col similar to spreadsheet software:
|
Due to some merged cell styles sometimes something like
A1;B2:C2;A3:C5
is needed to import to a data frame. Sadly this is currently not possible.Our selection of multiple cells always creates a square from the most left to the most right cell:
It would be beneficial if this would return
1, 5, 8
instead, or a data frame where all other cells areNA
. But if I remember correctly this requires at least modifications ofdims_to_dataframe()
and the question remains if this"A1;B2;C3"
should return a vector or a data frame of a single row or ... something entirely different.The text was updated successfully, but these errors were encountered: