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
Add from_dims to wb_dims #960
Conversation
Thanks for getting the ball rolling. I was thinking about something like this: library(openxlsx2)
dims <- wb_dims(from_dims = "A1", x = mtcars)
wb_dims(from_dims = dims, x = mtcars)
#> Error in wb_dims(from_dims = dims, x = mtcars): `from_col` / `from_row` should have length 1. and be positive. |
My intention is to be able to be able to further simplify the placement with Does that make sense? |
R/utils.R
Outdated
frow <- min(from_row) | ||
} else if (!is.null(above)) { | ||
fcol <- min(from_col) | ||
frow <- min(from_row) - above - nrow(args$x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this might require a column name correction
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh no, row_names
col_names
is a bit of a nightmare. Took me a while to figure it properly without these. (had to write my code on actual paper to figure it out)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hehe, yeah, you've created a complex monster with wb_dims()
. I have implemented something, maybe have a look if you have time. I probably wont have much time to work on this the upcoming week. Was thinking about corner cases, because ... why not wb_dims(from_dims = "A2:B3", below = 4, right = 5)
. But we can wait until anyone asks for it. Probably going with what we have and documenting it a bit should be enough for this PR.
I see what you mean. This is more complex than I thought. I can test it a bit more thoroughly once you have merged. Let's call it very experimental for now. |
Should work now: library(openxlsx2)
dims <- wb_dims(from_dims = "B4", right = 4)
wb <- wb_workbook()$add_worksheet()$add_data(dims = dims, x = mtcars, row_names = TRUE)
wb$add_fill(dims = wb_dims(from_dims = dims, x = mtcars, row_names = TRUE, cols = "mpg"), color = wb_color("yellow"))
if (interactive()) wb$open() |
I guess this is good to go. I will try to test more thoroughly after |
Thanks, merged |
Addresses part of #958 (comment)
I made
from_dims
independant fromfrom_col
/from_row
, but didn't really document it. Hopefully the error should be clear enough?