r [连接到Rstudio中的SQLite数据库] #R #SQLite #RStudio

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了r [连接到Rstudio中的SQLite数据库] #R #SQLite #RStudio相关的知识,希望对你有一定的参考价值。

## Import library
library(RSQLite)


## Connect to an existing database
Customers <- dbConnect(SQLite(), dbname = 'Customers.sqlite')


## Create and connect to a "virtual" in-memory database
Food <- dbConnect(SQLite())


## List all the tables currently in the database
dbListTables(Customers)


## Import CSV into SQLite database
'''
Currently, it seems that commas inside of a quoted string (like “Smith, John”) is still being recognized as a comma delimiter, so directly importing data from a CSV into a SQLite database is quite buggy. 
'''

Suppliers <- read.csv("./Suppliers.csv") # Import CSV into R dataframe
dbWriteTable(Customers, "suppliers", Suppliers) # Write data to a table in the Customers database


## Make a query in a SQL chunk
```{sql connection=Customers}
SELECT CustomerID, CustomerName, City
FROM customers
WHERE Country = "Germany";
```

以上是关于r [连接到Rstudio中的SQLite数据库] #R #SQLite #RStudio的主要内容,如果未能解决你的问题,请参考以下文章

使用 Rstudio windows 中的 R rJDBC 包连接到 hive(启用了 kerbero)

使用 ODBC 连接将 R Studio 连接到 IBM Netezza 数据库 [关闭]

远程 db2 服务器连接到 R studio

将 R 连接到 Vertica DB 以进行数据转换和建模?

在 Linux Centos 6.6 上使用 R 连接到 SQL Server

将 R 连接到 Redshift 时出错