-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.Rhistory
132 lines (132 loc) · 4.76 KB
/
.Rhistory
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
knitr::opts_chunk$set(echo = TRUE)
# CSV data file path:
path <- "C:/Users/mogde/Desktop/Git Repositories/CSC365/CSC365RealFinalProject/book32-listing-small.csv"
# TXT file to be written to:
out_path <- "C:/Users/mogde/Desktop/Git Repositories/CSC365/CSC365RealFinalProject/BookInsertStatements.sql"
library(tidyverse)
my.data <- read.csv(path, header=FALSE)
names(my.data) <- c("id_num", "title", "author", "num_copies", "category")
summary(my.data$num_copies)
out_file <- file(
description = out_path,
open="wt")
beginning <- "INSERT INTO Book (copyNum, title, author, numCopies, category) VALUES (\""
for (i in 1:nrow(my.data)) {
title <- my.data[i, "title"]
author <- my.data[i, "author"]
num_copies <- as.integer(my.data[i, "num_copies"])
category <- my.data[i, "category"]
for (j in 1:num_copies) {
line <- str_c(beginning, j, title, "\", \"", author, "\", ", num_copies, ", \"", category, "\");")
writeLines(line, out_file)
}
}
close(out_file, type="wt")
out_file <- file(
description = out_path,
open="wt")
beginning <- "INSERT INTO Book (copyNum, title, author, numCopies, category) VALUES ("
for (i in 1:nrow(my.data)) {
title <- my.data[i, "title"]
author <- my.data[i, "author"]
num_copies <- as.integer(my.data[i, "num_copies"])
category <- my.data[i, "category"]
for (j in 1:num_copies) {
line <- str_c(beginning, j,", \"", title, "\", \"", author, "\", ", num_copies, ", \"", category, "\");")
writeLines(line, out_file)
}
}
close(out_file, type="wt")
knitr::opts_chunk$set(echo = TRUE)
# CSV data file path:
path <- "C:/Users/mogde/Desktop/Git Repositories/CSC365/CSC365RealFinalProject/book32-listing-small.csv"
# TXT file to be written to:
out_path <- "C:/Users/mogde/Desktop/Git Repositories/CSC365/CSC365RealFinalProject/BookInsertStatements.sql"
library(tidyverse)
my.data <- read.csv(path, header=FALSE)
names(my.data) <- c("id_num", "title", "author", "num_copies", "category")
out_file <- file(
description = out_path,
open="wt")
beginning <- "INSERT INTO Book (copyNum, title, author, numCopies, category) VALUES ("
for (i in 1:nrow(my.data)) {
title <- my.data[i, "title"]
author <- my.data[i, "author"]
num_copies <- as.integer(my.data[i, "num_copies"])
category <- my.data[i, "category"]
for (j in 1:num_copies) {
line <- str_c(beginning,i,", ", j,", \"", title, "\", \"", author, "\", ", num_copies, ", \"", category, "\");")
writeLines(line, out_file)
}
}
close(out_file, type="wt")
out_file <- file(
description = out_path,
open="wt")
beginning <- "INSERT INTO Book (id, copyNum, title, author, numCopies, category) VALUES ("
for (i in 1:nrow(my.data)) {
title <- my.data[i, "title"]
author <- my.data[i, "author"]
num_copies <- as.integer(my.data[i, "num_copies"])
category <- my.data[i, "category"]
for (j in 1:num_copies) {
line <- str_c(beginning,i,", ", j,", \"", title, "\", \"", author, "\", ", num_copies, ", \"", category, "\");")
writeLines(line, out_file)
}
}
close(out_file, type="wt")
knitr::opts_chunk$set(echo = TRUE)
# CSV data file path:
path <- "C:/Users/mogde/Desktop/Git Repositories/CSC365/CSC365RealFinalProject/book32-listing-small.csv"
# TXT file to be written to:
out_path <- "C:/Users/mogde/Desktop/Git Repositories/CSC365/CSC365RealFinalProject/BookInsertStatements.sql"
library(tidyverse)
my.data <- read.csv(path, header=FALSE)
names(my.data) <- c("id_num", "title", "author", "num_copies", "category")
out_file <- file(
description = out_path,
open="wt")
beginning <- "INSERT INTO Book (id, copyNum, title, author, numCopies, category) VALUES ("
for (i in 1:nrow(my.data)) {
title <- my.data[i, "title"]
author <- my.data[i, "author"]
num_copies <- as.integer(my.data[i, "num_copies"])
category <- my.data[i, "category"]
for (j in 1:num_copies) {
line <- str_c(beginning,i,", ", j,", \"", title, "\", \"", author, "\", ", num_copies, ", \"", category, "\");")
writeLines(line, out_file)
}
}
close(out_file, type="wt")
out_file <- file(
description = out_path,
open="wt")
beginning <- "INSERT INTO Book (id, copyNum, title, author, category) VALUES ("
for (i in 1:nrow(my.data)) {
title <- my.data[i, "title"]
author <- my.data[i, "author"]
num_copies <- as.integer(my.data[i, "num_copies"])
category <- my.data[i, "category"]
for (j in 1:num_copies) {
line <- str_c(beginning,i,", ", j,", \"", title, "\", \"", author, "\", ", num_copies, ", \"",
category, "\");")
writeLines(line, out_file)
}
}
close(out_file, type="wt")
out_file <- file(
description = out_path,
open="wt")
beginning <- "INSERT INTO Book (id, copyNum, title, author, category) VALUES ("
for (i in 1:nrow(my.data)) {
title <- my.data[i, "title"]
author <- my.data[i, "author"]
num_copies <- as.integer(my.data[i, "num_copies"])
category <- my.data[i, "category"]
for (j in 1:num_copies) {
line <- str_c(beginning,i,", ", j,", \"", title, "\", \"", author, "\", \"",
category, "\");")
writeLines(line, out_file)
}
}
close(out_file, type="wt")