tidyverse / googlesheets4

Google Spreadsheets R API (reboot of the googlesheets package)
https://googlesheets4.tidyverse.org
Other
360 stars 53 forks source link

range_autofit() problems with longer cells #267

Closed even-of-the-hour closed 1 year ago

even-of-the-hour commented 2 years ago

I am seeing range_autofit() fail to give adequate space for longer cells. I frequently write long cells and column names to google sheets and sometimes see that the function doesn't quite give these long cells quite enough room (i.e., it does some expanding but not enough).

Example below:

library(googlesheets4)

my_df <- data.frame(column1 = LETTERS,
                    column2 = paste0(sample(letters, size = 15), collapse = ""),
                    `very very very long column 3` = paste0(sample(LETTERS, size = 20), collapse = ""),
                    `another very long long column` = paste0(sample(LETTERS, size = 15), collapse = " "))

gs4_create("testing-autofit",
           sheets = my_df)

range_autofit(ss = gs4_find("testing-autofit"),
              sheet = "my_df",
              dimension = "columns")

In the image below (my output for the above reprex), the first and second column look successfully fit, but things aren't quite right in the third and fourth. Is there a maximum width that range_autofit() starts to have trouble with?

image

jennybc commented 1 year ago

I seem to be doing exactly what the API docs say to do. So I conclude that whatever you're noticing is something that is out of my hands.

https://github.com/tidyverse/googlesheets4/blob/a9102de2eb02be6f7a5cf44fb112e87ed7fc7232/R/batch-update-requests.R#L81-L109

I could be persuaded of the need for a fix if someone could make an API call, e.g. via the API Explorer, that does better than range_autofit() in a way that suggests what we're doing wrong. But I don't see anything obvious to tweak or experiment with here.