1

I am trying to apply dtplyr to a SQL Server database.

I succeeded in applying dplyr as shown below, but I don't know how to apply dtplyr

How can I do this?

library(odbc)
library(DBI)
library(tidyverse)
library(dtplyr)
library(dbplyr)

con <- DBI::dbConnect(odbc::odbc(),
                      Driver    = "SQL Server", 
                      Server    = "address",
                      Database  = "dbname",
                      UID       = "ID",
                      PWD       = "password")

dplyr::tbl(con, dbplyr::in_schema("dbo", "table1"))
2
  • 1
    The example you provide seems related to dbplyr. What do you need dtplyr for? Commented Feb 13, 2021 at 17:07
  • 2
    dtplyr is for data processing using data.table, it doesn't handle the SQL Server connection. Commented Feb 13, 2021 at 17:15

1 Answer 1

1

The comments by @Waldi capture the essence of the matter. You can not use dtplyr with SQL Server as it only translates commands to data.table objects.

The official dtplyr documentation states:

The goal of dtplyr is to allow you to write dplyr code that is automatically translated to the equivalent ... data.table code

The official dbplyr documentation states:

It allows you to use remote database tables as if they are in-memory data frames by automatically converting dplyr code into SQL

Both dbplyr and dtplyr translate dplyr commands. Which one you use depends on whether you are working with data.table type objects (in R memory) or remote SQL databases (whichever flavor of SQL you prefer).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.