I want to delete all columns of a dataframe which contain NA values only, within the dbplyr
syntax.
With the normal R syntax this is no problem, see here: Remove columns from dataframe where ALL values are NA
Here is a possibility in R:
library(tidyverse)
library(DBI)
library(dbplyr)
df <- data.frame(a = NA,
b = seq(1:5),
c = c(rep(1, 4), NA))
df %>% purrr::discard(~all(is.na(.)))
# desired output:
# A tibble: 5 × 2
b c
<int> <dbl>
1 1 1
2 2 1
3 3 1
4 4 1
5 5 NA
But now I want to do this in the dbplyr
syntax. For this the following example:
# Creating test database
con <- dbConnect(RSQLite::SQLite(), "")
# Inserting test table
dbWriteTable(con, "df", df)
con %>%
tbl("df") %>%
purrr::discard(~all(is.na(.))) %>%
collect()
#Error in UseMethod("collect") :
# no applicable method for 'collect' applied to an object of class "list"
Can anyone help me find a solution within dbplyr
?