-
Notifications
You must be signed in to change notification settings - Fork 2
/
SQLite.Rmd
54 lines (45 loc) · 1.2 KB
/
SQLite.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
---
title: "SQLite"
author: "Brian Yandell"
date: "2023-07-18"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
library(tidyverse)
library(DBI)
library(RSQLite)
library(dbplyr)
```
```{r}
dirpath <- file.path("big")
traitData <- readRDS(file.path(dirpath, "traitData.rds"))
traitStats <- readRDS(file.path(dirpath, "traitStats.rds"))
traitSignal <- readRDS(file.path(dirpath, "traitSignal.rds"))
```
```{r}
mydb <- RSQLite::dbConnect(RSQLite::SQLite(), "traitData.sqlite")
RSQLite::dbDisconnect(mydb)
```
```{r eval = FALSE}
mydb <- RSQLite::dbConnect(RSQLite::SQLite(), "traitData.sqlite")
RSQLite::dbWriteTable(mydb, value = traitData, name = "traitData",
overwrite = TRUE,
indexes = list(c("dataset", "trait")))
RSQLite::dbListTables(mydb)
RSQLite::dbDisconnect(mydb)
```
```{r}
mydb <- RSQLite::dbConnect(RSQLite::SQLite(), "traitData.sqlite")
head(dplyr::tbl(mydb, "traitdata"))
```
```{r}
mydb <- RSQLite::dbConnect(RSQLite::SQLite(), "traitData.sqlite")
tmp <- dplyr::collect(dplyr::filter(dplyr::tbl(mydb, "traitdata"),
dataset == "Physio", trait == "BW_6wk"))
```
```{r}
str(tmp)
```