Skip to content

Commit 062b31b

Browse files
committed
Copyedits
1 parent e048a3a commit 062b31b

File tree

4 files changed

+31
-24
lines changed

4 files changed

+31
-24
lines changed

README.md

+14-14
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
- [Accessing data with queries](#accessing-data-with-queries)
88
- [Basic queries](#basic-queries)
99
- [Filtering](#filtering)
10-
- [**Challenge 1**: Large bois](#challenge-1-large-bois)
10+
- [**Challenge 1**](#challenge-1)
1111
- [Building complex queries](#building-complex-queries)
1212
- [Sorting](#sorting)
1313
- [**Challenge 2**](#challenge-2)
@@ -95,9 +95,9 @@ and atomic transactions. It eliminates ambiguity by forbidding NULLs.
9595

9696
4. Solution: Normalize the data by breaking it into multiple tables
9797

98-
| Animals | Sightings |
99-
|------------------------------|--------------------------------|
100-
| ![](images/animals_half.png) | ![](images/sightings_half.png) |
98+
Animals Sightings
99+
------------------------------ --------------------------------
100+
![](images/animals_half.png) ![](images/sightings_half.png)
101101

102102
- Every row of every table contains unique information
103103
- Normalization is a continuum. We could normalize this data
@@ -214,7 +214,7 @@ and atomic transactions. It eliminates ambiguity by forbidding NULLs.
214214
WHERE (species_id = 'DM') OR (species_id = 'DO') OR (species_id = 'DS');
215215
```
216216

217-
## **Challenge 1**: Large bois
217+
## **Challenge 1**
218218

219219
Get all of the individuals in Plot 1 that weighed more than 75 grams,
220220
telling us the date, species id code, and weight (in kg).
@@ -558,7 +558,7 @@ sqlite3 # enter sqlite prompt
558558
```
559559

560560
``` sql
561-
select * from species where taxa == 'Rodent';
561+
SELECT * FROM species WHERE taxa = 'Rodent';
562562
```
563563

564564
2. Output to .csv file
@@ -569,7 +569,7 @@ sqlite3 # enter sqlite prompt
569569
```
570570

571571
``` sql
572-
select * from species where taxa == 'Rodent';
572+
SELECT * FROM species WHERE taxa = 'Rodent';
573573
```
574574

575575
``` bash
@@ -588,47 +588,47 @@ sqlite3 # enter sqlite prompt
588588

589589
2. Import libraries
590590

591-
``` {.r org-language="R"}
591+
``` r
592592
library("DBI")
593593
library("RSQLite")
594594
```
595595

596596
3. FYI, use namespaces explicitly
597597

598-
``` {.r org-language="R"}
598+
``` r
599599
con <- DBI::dbConnect(RSQLite::SQLite(), "../data/portal_mammals.sqlite")
600600
```
601601

602602
4. Show tables
603603

604-
``` {.r org-language="R"}
604+
``` r
605605
dbListTables(con)
606606
```
607607

608608
5. Show column names
609609

610-
``` {.r org-language="R"}
610+
``` r
611611
dbListFields(con, "species")
612612
```
613613

614614
6. Get query results at once
615615

616-
``` {.r org-language="R"}
616+
``` r
617617
df <- dbGetQuery(con, "SELECT * FROM surveys WHERE year = 2000")
618618
head(df)
619619
```
620620

621621
7. Use parameterized queries
622622

623-
``` {.r org-language="R"}
623+
``` r
624624
df <- dbGetQuery(con, "SELECT * FROM surveys WHERE year = ? AND (month > ? AND month < ?)",
625625
params = c(2000, 4, 10))
626626
head(df)
627627
```
628628

629629
8. Disconnect
630630

631-
``` {.r org-language="R"}
631+
``` r
632632
dbDisconnect(con)
633633
```
634634

README.org

+13-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
#+BEGIN_SRC sql
77
#+END_SRC
88

9+
* COMMENT Fix R formatting in final version
10+
* COMMENT Add Python example code
11+
* COMMENT Rethink narrative: Start by building database from CSVs?
12+
e.g. http://swcarpentry.github.io/sql-novice-survey/09-create/index.html
13+
* COMMENT Is there a better database (for me)?
14+
915
* COMMENT SQL interaction in Emacs
1016
1. Start SQLite inferior process
1117
~M-x sql-sqlite~
@@ -37,8 +43,8 @@ There are two aspects of "correctness": Enforcing consistency and eliminating am
3743

3844
4. Solution: Normalize the data by breaking it into multiple tables
3945

40-
| Animals | Sightings |
41-
|----------------------------------+------------------------------------+
46+
| Animals | Sightings |
47+
|------------------------------+--------------------------------|
4248
| [[file:images/animals_half.png]] | [[file:images/sightings_half.png]] |
4349

4450
- Every row of every table contains unique information
@@ -136,7 +142,7 @@ There are two aspects of "correctness": Enforcing consistency and eliminating am
136142
WHERE (species_id = 'DM') OR (species_id = 'DO') OR (species_id = 'DS');
137143
#+END_SRC
138144

139-
** *Challenge 1*: Large bois
145+
** *Challenge 1*
140146
Get all of the individuals in Plot 1 that weighed more than 75 grams, telling us the date, species id code, and weight (in kg).
141147

142148
** Building complex queries
@@ -425,7 +431,7 @@ sqlite3 # enter sqlite prompt
425431
#+END_SRC
426432

427433
#+BEGIN_SRC sql
428-
select * from species where taxa == 'Rodent';
434+
SELECT * FROM species WHERE taxa = 'Rodent';
429435
#+END_SRC
430436

431437
2. Output to .csv file
@@ -435,7 +441,7 @@ sqlite3 # enter sqlite prompt
435441
#+END_SRC
436442

437443
#+BEGIN_SRC sql
438-
select * from species where taxa == 'Rodent';
444+
SELECT * FROM species WHERE taxa = 'Rodent';
439445
#+END_SRC
440446

441447
#+BEGIN_SRC bash
@@ -573,7 +579,8 @@ pandoc -f markdown --toc --toc-depth=2 -s tmp.md -o README.md
573579

574580
** Find and replace code block markers in final document (if applicable)
575581
#+BEGIN_EXAMPLE
576-
M-x qrr " {.python}" "python"
582+
M-x qrr " {.r org-language="R"}" "r"
583+
M-x qrr " {.r}" "r"
577584
M-x qrr " {.bash}" "bash"
578585
#+END_EXAMPLE
579586

images/database_alignment.jpg

220 KB
Loading

scripts/python_example.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
c = conn.execute(query, args)
2323
results = c.fetchall()
2424

25-
# Parameter substitution with named parameters; don't create intermediate
25+
# Parameter substitution with named parameters; doesn't create intermediate
2626
# cursor variable.
2727
with conn:
28-
query_named = "SELECT * FROM surveys WHERE species_id = :id AND year > :year ORDER BY hindfoot_length;"
29-
args_named = {"id": "DM",
28+
query = "SELECT * FROM surveys WHERE species_id = :id AND year > :year ORDER BY hindfoot_length;"
29+
named_args = {"id": "DM",
3030
"year": 1995}
3131

32-
results = conn.execute(query_named, args_named).fetchall()
32+
results = conn.execute(query, named_args).fetchall()
3333

3434
# Iteration on results from implicit cursor
3535
with conn:

0 commit comments

Comments
 (0)