如何使用 SQL 服务器数据库应用 dtplyr
How to apply dtplyr with SQL Server database
我正在尝试将 dtplyr 应用于 SQL 服务器数据库。
如下图我申请dplyr成功了,但是不知道怎么申请dtplyr
我该怎么做?
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"))
@Waldi 的评论抓住了问题的本质。您可以 不 将 dtplyr 与 SQL 服务器一起使用,因为它只将命令转换为 data.table
个对象。
官方dtplyr documentation声明:
The goal of dtplyr is to allow you to write dplyr code that is automatically translated to the equivalent ... data.table code
官方 dbplyr documentation 声明:
It allows you to use remote database tables as if they are in-memory data frames by automatically converting dplyr code into SQL
dbplyr 和 dtplyr 都转换 dplyr 命令。您使用哪一个取决于您使用的是 data.table
类型对象(在 R 内存中)还是远程 SQL 数据库(您喜欢哪种类型的 SQL)。
我正在尝试将 dtplyr 应用于 SQL 服务器数据库。
如下图我申请dplyr成功了,但是不知道怎么申请dtplyr
我该怎么做?
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"))
@Waldi 的评论抓住了问题的本质。您可以 不 将 dtplyr 与 SQL 服务器一起使用,因为它只将命令转换为 data.table
个对象。
官方dtplyr documentation声明:
The goal of dtplyr is to allow you to write dplyr code that is automatically translated to the equivalent ... data.table code
官方 dbplyr documentation 声明:
It allows you to use remote database tables as if they are in-memory data frames by automatically converting dplyr code into SQL
dbplyr 和 dtplyr 都转换 dplyr 命令。您使用哪一个取决于您使用的是 data.table
类型对象(在 R 内存中)还是远程 SQL 数据库(您喜欢哪种类型的 SQL)。