-
Notifications
You must be signed in to change notification settings - Fork 53
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
Allow sheet_append to match existing sheet format (or add append option to range_write) #204
Comments
I would like to boost this. If you are attempting to following along the Rstudio persistent data blogpost and using sheet_append your data never loads in, since it is formatted differently. |
I feel like these two comments are sort of conflating 2 things. The original issue is about ... inheriting style from the row above. Given the API feature I am using ( The second comment (re: the persistent data blogpost) sounds like there are some issues around datetimes. It should probably be its own issue. The blog post is also rather short of details. In both cases, though, I would be able to explore and maybe improve things much faster with a proper reprex: https://googlesheets4.tidyverse.org/articles/articles/googlesheets4-reprex.html Without this, it's rather daunting to dig into this, as I need to invent a Sheet that has the properties I think you're talking about (what sort of formats do they have in mind?), initialize the way I think you are doing, and send new data the way I think you're doing. It's easy for us to not be thinking about the same things. |
Hello @jennybc I can't comment on @alexbhatt 's point as I don't fully understand it! I did think about a reprex in my original comment but I am struggling to work out how to do it as it needs an existing googlesheet file, with a table that contains some formatting. My only Google account is a work G Suite account and they're a bit funny about sharing files externally - The sheet link explicitly just in case you need to use this instead: https://docs.google.com/spreadsheets/d/1m-g8U2YkG4QGrUNXKk9eKoBnsWgZ_tdJFjQhwDC_Y88/edit?usp=sharing
In case this doesn't work, what I have is a file with two sheets. The first has a table where only the table itself is formatted, the other sheet formats the entire columns as per the following two images: When I use But what I would like is either of: I don't actually mind whether it picks up the formatting from the row above (so the Hope that's clear(er)? |
Yes thanks that helps! |
@jennybc, while creating the reprex, I happened to solve the problem, possibly with a workaround? Link to the reprex github: https://github.com/alexbhatt/ibd_tracker/tree/reprex |
I haven't delved into the date time issue, but will have a look. But now we no longer clobber, e.g. pre-existing gridlines, when appending. I achieved this by simply sending a more precise description of the format information that we potentially send, i.e. by not asserting that we were sending the entire cell format. I'm still sending the |
I can't see the problem when appending in the presence of dates or date times. I suspect it's a usage problem, with unnecessary trips through a character representation. TL;DR If you have a library(googlesheets4)
library(googledrive)
# hidden auth chunk here
ss <- gs4_create("sheet_append-fun-with-dates-and-datetimes")
#> ✓ Creating new Sheet: "sheet_append-fun-with-dates-and-datetimes".
to_start <- tibble::tibble(
foo = LETTERS[1:2],
datetimes = Sys.time() - (0:1) * 3600,
dates = Sys.Date() - (0:1)
)
to_start
#> # A tibble: 2 x 3
#> foo datetimes dates
#> <chr> <dttm> <date>
#> 1 A 2021-07-15 18:43:43 2021-07-15
#> 2 B 2021-07-15 17:43:43 2021-07-14
to_start %>%
write_sheet(ss, sheet = 1)
#> ✓ Writing to "sheet_append-fun-with-dates-and-datetimes".
#> ✓ Writing to sheet 'Sheet1'.
dat <- read_sheet(ss, col_types = "cTD")
#> ✓ Reading from "sheet_append-fun-with-dates-and-datetimes".
#> ✓ Range 'Sheet1'.
dat
#> # A tibble: 2 x 3
#> foo datetimes dates
#> <chr> <dttm> <date>
#> 1 A 2021-07-16 01:43:43 2021-07-15
#> 2 B 2021-07-16 00:43:43 2021-07-14
to_append <- tibble::tibble(
foo = LETTERS[3:4],
datetimes = Sys.time() - (2:3) * 3600,
dates = Sys.Date() - (2:3)
)
to_append
#> # A tibble: 2 x 3
#> foo datetimes dates
#> <chr> <dttm> <date>
#> 1 C 2021-07-15 16:43:45 2021-07-13
#> 2 D 2021-07-15 15:43:45 2021-07-12
ss %>%
sheet_append(data = to_append)
#> ✓ Writing to "sheet_append-fun-with-dates-and-datetimes".
#> ✓ Appending 2 rows to 'Sheet1'.
dat <- read_sheet(ss, col_types = "cTD")
#> ✓ Reading from "sheet_append-fun-with-dates-and-datetimes".
#> ✓ Range 'Sheet1'.
dat
#> # A tibble: 4 x 3
#> foo datetimes dates
#> <chr> <dttm> <date>
#> 1 A 2021-07-16 01:43:43 2021-07-15
#> 2 B 2021-07-16 00:43:43 2021-07-14
#> 3 C 2021-07-15 23:43:45 2021-07-13
#> 4 D 2021-07-15 22:43:45 2021-07-12
googledrive::drive_rm(ss)
#> File deleted:
#> • 'sheet_append-fun-with-dates-and-datetimes'
#> <id: 1e_J4-arZCifqLPzpsPESWEGphk9WUprXmR6SvcPBFIY> Created on 2021-07-15 by the reprex package (v2.0.0.9000) |
When I use
sheet_append
to add rows to an existing sheet, the new rows are all format free - even if the table in the existing sheet contains formatting. It would be nice to have areformat = FALSE
option forsheet_append
similar torange_write
.I think the lack of this option is by design - I assume
sheet_append
is literally adding new rows to the sheet as opposed to writing over existing rows - hence they contain no formatting. But, often I am writing to an existing file with formatting and it would be nice if I could usesheet_append
without having the blank formatting (or add anappend
option torange_write
, if that's easier). Currently I just userange_write
with thereformat = FALSE
option but then I need to do a bit of extra faff to get the starting row from the existing file by reading it in and then usingnrow
- but the file is often very big and takes ages to read in to do that. If it's not too much hassle to fudge a background solution to one of those functions, it would be great.The text was updated successfully, but these errors were encountered: