Skip to content

Explicit NULL cells disappear when writing #203

@py9mrg

Description

@py9mrg

Recently I have been trying to write some results to existing Google Sheet files and have found two quirks. I think probably by design but I thought I'd raise them as potential features / options to existing functions that can make life a bit easier for the user.

First: writing NULL columns as empty columns, not skipping them.

Let's say I have a tibble of list-columns something like:

tmp <- tibble(A = list(NULL, NULL, NULL), B = list(1, 2, 3))
tmp
# A tibble: 3 x 2
  A      B        
  <list> <list>   
1 <NULL> <dbl [1]>
2 <NULL> <dbl [1]>
3 <NULL> <dbl [1]>

When I write this to a sheet using (as far as I can tell) any of the writing functions, the NULL column just gets skipped rather than a blank column being written. This can mean columns get written in the wrong place - e.g. in the above example column B would be written in column A of the Google Sheet because column A would be ignored rather than a blank column being written. Yet a 3 x 2 sheet will result - just with the B column in the A position and a blank column at the end. If that makes sense?! So it's like write_sheet knows about the NULL column and makes space for it, but then doesn't actually write it.

Often I am reading in data with some empty columns (which get read in as a NULL column), doing some wrangling, and then writing to a new and/or existing sheet. It would be nice if the "round-trip" was symmetrical in the sense that empty columns get read in as NULL and NULL columns get written as empty columns. Currently I have to force coercion to character when reading with col_types = 'c' and then use mutate(across(everything(), as.list)) to coerce everything back into list columns - then the NULL columns become character columns of NA, which get written as blank values as intended.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐛an unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions