• R/O
  • SSH

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisãod382ccb02f97a48ef8b4835b59bd04ba6d96458e (tree)
Hora2020-07-07 05:28:51
AutorLorenzo Isella <lorenzo.isella@gmai...>
CommiterLorenzo Isella

Mensagem de Log

A small script to properly create an sqlite database and disconnect from it.

Mudança Sumário

Diff

diff -r 5473c2bfc109 -r d382ccb02f97 R-codes/store_sql_lite.R
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/R-codes/store_sql_lite.R Mon Jul 06 22:28:51 2020 +0200
@@ -0,0 +1,43 @@
1+rm(list=ls())
2+
3+library(tidyverse)
4+library(haven)
5+library(DBI)
6+library(RSQLite)
7+library(dbplyr)
8+
9+
10+source("/home/lorenzo/myprojects-hg/R-codes/stat_lib.R")
11+
12+
13+df <- read_dta("NTM_hs6_2010_2018_v.12.dta") %>% as_tibble
14+
15+saveRDS(df, "ntm_fixed.RDS")
16+
17+write_csv(df, "ntm.csv")
18+
19+
20+## see https://themockup.netlify.app/posts/2019-04-28-nflfastr-dbplyr-rsqlite/
21+
22+
23+## First create the database
24+mydb <- DBI::dbConnect(RSQLite::SQLite(), dbname="ntm.sqlite")
25+
26+###Then write content to the database. Give a name to the table.
27+DBI::dbWriteTable(mydb,"ntm_database",df, overwrite=T)
28+
29+## list the table
30+print("The content of the database is,")
31+print(DBI::dbListTables(mydb))
32+
33+
34+### Probably I should run this at the end.
35+## See https://cran.r-project.org/web/packages/RSQLite/vignettes/RSQLite.html
36+
37+
38+dbDisconnect(mydb)
39+unlink("ntm.sqlite")
40+
41+
42+
43+print("So far so good")