How to select all columns in dplyr/sql?

16,822

As @AntoniosK pointed out I do not know why you would like to do that. However, have you tried everything?:

some_dataframe <- ...
select(everything())

For instance:

select(iris, everything()) # or
iris %>% select(everything())
Share:
16,822
Robert Kirsten
Author by

Robert Kirsten

Updated on July 18, 2022

Comments

  • Robert Kirsten
    Robert Kirsten almost 2 years

    I am connecting a MySQL data base with dplyr and handle the data with dplyr and the %>% operatot subsequently.

    conDplyr <- src_mysql(user = db_user, password = db_pw, dbname = db_name, host = db_host, port = some_port)
    

    As long as I select a certain number of columns but all, it works!

    dat <- conDplyr %>%
     tbl('table_name') %>%
     select(c1, c2, c3, c4) %>%
     filter(!is.null(c4))
    

    Now, I ran over a use case, in which I need to select all columns (whole table). All tutorials I found (about dplyr) handled this by selecting the whole dataframe (which I do not have)

    some_dataframe <- ...
    select(some_dataframe)
    

    I have not found any suggestions in combination with databases. Perhaps the day was too long. Does anybody could help me please?

    Best Rob

    conDplyr <- src_mysql(...)
    dat <- conDplyr %>%
    tbl('table_name') %>%
    select(everything()) %>%
    filter(!is.null(ean))
    

    works just fine. Thanks! If I leave out the select the query results in an error (non-defined columns selected). Again, I did not just want to work with a already existing data frame, but with a table queried from a database, that`s why I am have to do, correct me if I am wrong, an select.