r 在Rstudio中使用SQLite

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了r 在Rstudio中使用SQLite相关的知识,希望对你有一定的参考价值。

##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的主要内容,如果未能解决你的问题,请参考以下文章