Wrapper function to read table from default or custom schema, and return NA by default if an error is encountered.

db.read_table(con, table, schema = NA, collect = TRUE, error_value = NA)

Arguments

con

An object that inherits from DBIConnection-class, typically generated by dbConnect()

table

A character string specifying the DBMS table name.

schema

A character string specifying the schema in which the table is nested.

collect

A logical specifying whether the query results should be collected into memory or left as a lazy query.

error_value

Error value to return if dbReadTable() fails. Default is NA.

Value

If the SQL query executes successfully, the return value will be an object of class tibble. If an error is encountered, the return value will be inherited from the error_value argument provided (default is NA).

Examples

con <- connect_sqlite(auto_disconnect = FALSE)
dplyr::copy_to(con, iris, "df", temporary = FALSE)
db.read_table(con = con, table = 'df')
#> Reading table df
#> # A tibble: 150 × 5
#>    Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#>           <dbl>       <dbl>        <dbl>       <dbl> <chr>  
#>  1          5.1         3.5          1.4         0.2 setosa 
#>  2          4.9         3            1.4         0.2 setosa 
#>  3          4.7         3.2          1.3         0.2 setosa 
#>  4          4.6         3.1          1.5         0.2 setosa 
#>  5          5           3.6          1.4         0.2 setosa 
#>  6          5.4         3.9          1.7         0.4 setosa 
#>  7          4.6         3.4          1.4         0.3 setosa 
#>  8          5           3.4          1.5         0.2 setosa 
#>  9          4.4         2.9          1.4         0.2 setosa 
#> 10          4.9         3.1          1.5         0.1 setosa 
#> # … with 140 more rows