Skip to content

Commit 251ecf3

Browse files
restoring repo contents
1 parent 301e739 commit 251ecf3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+6848
-0
lines changed

Diff for: .Rbuildignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
^.*\.Rproj$
2+
^\.Rproj\.user$

Diff for: .gitignore

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# History files
2+
.Rhistory
3+
.Rapp.history
4+
5+
# Session Data files
6+
.RData
7+
8+
# User-specific files
9+
.Ruserdata
10+
11+
# Example code in package build process
12+
*-Ex.R
13+
14+
# Output files from R CMD build
15+
/*.tar.gz
16+
17+
# Output files from R CMD check
18+
/*.Rcheck/
19+
20+
# RStudio files
21+
.Rproj.user/
22+
23+
# produced vignettes
24+
vignettes/*.html
25+
vignettes/*.pdf
26+
27+
# OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3
28+
.httr-oauth
29+
30+
# knitr and R markdown default cache directories
31+
*_cache/
32+
/cache/
33+
34+
# Temporary files created by R markdown
35+
*.utf8.md
36+
*.knit.md
37+
38+
# R Environment Variables
39+
.Renviron
40+
41+
# Mac Files
42+
.DS_Store
43+
vignettes/.DS_Store
44+

Diff for: DESCRIPTION

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
Package: cropDiffusionR
2+
Type: Package
3+
Title: Exploring the Diffusion of Agricultural Crops
4+
Version: 1.0.0
5+
Date: 2022-09-23
6+
Authors@R:
7+
c(
8+
person(given = "Andrew",
9+
family = "Gillreath-Brown",
10+
role = c("aut", "cre"),
11+
email = "[email protected]",
12+
comment = c(ORCID = "0000-0002-2272-5542")),
13+
person(given = "Timothy",
14+
family = "Kohler",
15+
role = c("aut", "ctb"),
16+
email = "[email protected]",
17+
comment = c(ORCID = "0000-0002-3414-6660"))
18+
)
19+
Maintainer: Andrew Gillreath-Brown <[email protected]>
20+
Description: This R package repository is to accompany the submission for Gillreath-Brown and Kohler 2022, which examines the effects temperature on the spread of maize agriculture to the southwestern United States.
21+
License: MIT + file LICENSE
22+
Depends:
23+
magrittr,
24+
R (>= 3.5.0),
25+
vegan
26+
Imports:
27+
rebus.numbers,
28+
leaflet,
29+
sp,
30+
rgdal,
31+
plotly,
32+
RColorBrewer,
33+
here,
34+
lubridate,
35+
units,
36+
rcarbon,
37+
DescTools,
38+
sf,
39+
readr,
40+
purrr,
41+
dplyr,
42+
tibble,
43+
tidyr,
44+
raster,
45+
reshape2,
46+
mgcv,
47+
ggplot2,
48+
maps,
49+
ggh4x,
50+
usmap,
51+
shadowtext,
52+
knitr,
53+
data.table,
54+
httr,
55+
ggpubr,
56+
gganimate,
57+
ggsci,
58+
p3k14c,
59+
terra
60+
Remotes:
61+
zeehio/facetscales,
62+
Archaeo-Programmer/paleomat
63+
LazyData: TRUE
64+
Suggests: testthat
65+
Encoding: UTF-8
66+
URL: https://github.com/Archaeo-Programmer/cropDiffusionR
67+
BugReports: https://github.com/Archaeo-Programmer/cropDiffusionR/issues
68+
RoxygenNote: 7.2.1
69+
Roxygen: list(markdown = TRUE)

Diff for: LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Andrew Gillreath-Brown
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Diff for: NAMESPACE

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Generated by roxygen2: do not edit by hand
2+
3+
export(extract_GDD)
4+
export(extract_diffusion)
5+
export(extract_earliest_crop)
6+
importFrom(magrittr,`%<>%`)
7+
importFrom(magrittr,`%>%`)

Diff for: R/data.R

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#' Annual Accumulated Growing Degree Days from SAGE.
2+
#'
3+
#' A `raster` containing annual global accumulated growing degree days for the year with a base temperature of 5°C.
4+
#'
5+
#' @format An object of class `RasterLayer`.
6+
#' @source \url{https://sage.nelson.wisc.edu/data-and-models/atlas-of-the-biosphere/mapping-the-biosphere/ecosystems/growing-degree-days/}
7+
"global_gdd"
8+
9+
#' North American Southwest Ancient Maize Database.
10+
#'
11+
#' A `tibble` containing calibrated radiocarbon data for ancient maize macrosamples across the North American Southwest.
12+
#'
13+
#' @format An object of class `tibble`.
14+
#' @source \url{https://doi.org/10.1038/s41597-022-01118-7}
15+
#' @source \url{https://doi.org/10.48512/XCV8459173}
16+
#' @source \url{http://en.ancientmaize.com/}
17+
#' @source \url{https://www.canadianarchaeology.ca/}
18+
#' @references
19+
#' Bocinsky, R. Kyle, Darcy Bird, and Erick Robinson, (2020). Compendium of R code and data for p3k14c: A synthetic global database of archaeological radiocarbon dates. Accessed on September 12, 2022. https://github.com/people3k/p3k14c
20+
#'
21+
#' Bird, D., Miranda, L., Vander Linden, M. et al. p3k14c, a synthetic global database of archaeological radiocarbon dates. Sci Data 9, 27 (2022). https://doi.org/10.1038/s41597-022-01118-7
22+
#'
23+
#' Blake, M., B. Benz, D. Moreiras, L. Masur, N. Jakobsen and R. Wallace. 2017. Ancient Maize Map, Version 2.1: An Online Database and Mapping Program for Studying the Archaeology of Maize in the Americas. http://en.ancientmaize.com/. Laboratory of Archaeology, University of B.C., Vancouver. Accessed on February 24, 2021.
24+
#'
25+
#' Martindale, Andrew, Richard Morlan, Matthew Betts, Michael Blake, Konrad Gajewski, Michelle Chaput, Andrew Mason, and Pierre Vermeersch (2016) Canadian Archaeological Radiocarbon Database (CARD 2.1), accessed September 10, 2022.
26+
"maizeDB"
27+
28+
#' Annual Accumulated Growing Degree Days from WorldClim.
29+
#'
30+
#' A `raster` containing annual accumulated growing degree days for the year with a base temperature of 10°C and maximum temperature of 30°C.
31+
#' GDD was calculated from the tavg 30 seconds (~1 \ifelse{html}{\out{km<sup>2</sup>}}{\eqn{km^2}}).
32+
#'
33+
#' @format An object of class `RasterLayer`.
34+
#' @source \url{https://www.worldclim.org/data/worldclim21.html}
35+
"NASW_gdd"
36+
37+
#' Southwestern United States and Mexico States Polygon.
38+
#'
39+
#' A `MULTIPOLYGON` containing the state boundaries for the southwestern United States (i.e., Arizona, Colorado, New Mexico, and Utah) and Mexico.
40+
#'
41+
#' @format An object of class `sfc_MULTIPOLYGON`.
42+
#' @source \url{https://www.arcgis.com/home/item.html?id=ac9041c51b5c49c683fbfec61dc03ba8}
43+
"usa_mexico_states"
44+
45+
#' Digital Elevation Model for the Southwestern United States and Mexico States.
46+
#'
47+
#' A `raster` containing elevation for the southwestern United States (i.e., Arizona, Colorado, New Mexico, and Utah) and Mexico.
48+
#'
49+
#' @format An object of class `RasterLayer`.
50+
#' @source \url{https://github.com/jhollist/elevatr}
51+
"NASW_elevation"
52+

Diff for: R/extract_GDD.R

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#' @name extract_GDD
2+
#' @title Extract annual accumulated growing degree days
3+
#'
4+
#' @description `extract_GDD()` extracts annual accumulated growing degree days from WorldClim 2.0 for 1970 to 2000 at site locations.
5+
#'
6+
#' @param sites A data.frame with an ID and sfc_Point geometry containing site locations.
7+
#' @return A tibble with growing degree days for each ID.
8+
#' @importFrom magrittr `%<>%` `%>%`
9+
#' @export
10+
extract_GDD <-
11+
function(sites) {
12+
13+
# Get annual accumulated growing degree days.
14+
terra::extract(x = cropDiffusionR::NASW_gdd,
15+
y = sites) %>%
16+
dplyr::bind_cols(LabID = sites$LabID, GDD = .)
17+
18+
}

Diff for: R/extract_diffusion.R

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#' @name extract_diffusion
2+
#' @title Extract latitudinal diffusion of a crop
3+
#'
4+
#' @description `extract_diffusion()` extracts the diffusion of a crop by latitude.
5+
#'
6+
#' @param database A data.frame containing a crop database.
7+
#' @param direction A string stating the direction of diffusion (i.e., north).
8+
#' @return A tibble that has the frontier of a crop through time using 100 year time bins.
9+
#' @importFrom magrittr `%<>%` `%>%`
10+
#' @export
11+
extract_diffusion <-
12+
function(database, direction = "north") {
13+
database <- database %>%
14+
# Create 100 year bins.
15+
dplyr::mutate(bin = cut(
16+
MedianBP,
17+
breaks = seq(
18+
plyr::round_any(min(MedianBP), 100, f = floor),
19+
plyr::round_any(max(MedianBP), 100, f = ceiling),
20+
by = 100
21+
),
22+
include.lowest = TRUE
23+
))
24+
25+
if (direction == "north")
26+
database %>%
27+
dplyr::group_by(bin) %>%
28+
dplyr::slice_max(Lat) %>%
29+
dplyr::slice_max(MedianBP) %>%
30+
dplyr::ungroup() %>%
31+
dplyr::arrange(desc(MedianBP)) %>%
32+
dplyr::filter(Lat == cummax(Lat)) %>%
33+
dplyr::group_by(SiteName) %>%
34+
dplyr::slice_min(Date, with_ties = FALSE) %>%
35+
dplyr::ungroup() %>%
36+
dplyr::arrange(Date)
37+
else
38+
stop(
39+
"The direction is not north. Please use north for direction. We will be updating this function in the fugure to do other directions."
40+
)
41+
}

Diff for: R/extract_earliest_crop.R

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#' @name extract_earliest_crop
2+
#' @title Extract earliest date for a crop by province
3+
#'
4+
#' @description `extract_earliest_crop()` extracts the sample with the earliest date for a crop by province.
5+
#'
6+
#' @param database A data.frame containing the crop database.
7+
#' @return A tibble that contains the earliest date for each province.
8+
#' @importFrom magrittr `%<>%` `%>%`
9+
#' @export
10+
extract_earliest_crop <-
11+
function(database) {
12+
database %>%
13+
dplyr::group_by(Province) %>%
14+
dplyr::slice_max(MedianBP) %>%
15+
dplyr::ungroup() %>%
16+
dplyr::arrange(Latitude)
17+
18+
}

Diff for: README.md

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# cropDiffusionR: Exploring the Diffusion of Agricultural Crops
2+
3+
`cropDiffusionR` is an *R* package implementing functions to perform
4+
analysis on the relationship between maize agriculture and temperature changes in prehistory.
5+
6+
This is the official R package for [cropDiffusionR](https://github.com/Archaeo-Programmer/cropDiffusionR),
7+
which contains all code associated with the analyses described and presented, including figures and tables, in Gillreath-Brown et al. 2022 (submitted):
8+
9+
Gillreath-Brown, A., and T. A. Kohler (2022). Children of El Niño: How Maize Farmers in the US Southwest Grew and Prospered under El Niño but Suffered under La Niña. Submitted to *KIVA* for review.
10+
11+
All code for analysis, figures, and tables is in [Maize_Analysis.Rmd](vignettes/Maize_Analysis.Rmd).
12+
13+
## Installation
14+
15+
You can install `cropDiffusionR` from GitHub with these lines of R code (Windows users are recommended to install a separate program, Rtools, before proceeding with this step):
16+
17+
``` r
18+
if (!require("devtools")) install.packages("devtools")
19+
devtools::install_github("Archaeo-Programmer/cropDiffusionR")
20+
```
21+
22+
## Repository Contents
23+
24+
The [:file\_folder: vignettes](vignettes) directory contains:
25+
26+
- [:page\_facing\_up: Maize_Analysis](vignettes/Maize_Analysis.Rmd): R
27+
Markdown document with all analysis and code to reproduce the figures and tables for the submitted paper (Gillreath-Brown and Kohler 2022).
28+
It also has a rendered version, [Maize_Analysis.html](vignettes/Maize_Analysis.html), which shows figure and table output.
29+
- [:file\_folder: figures](vignettes/figures): Plots, figures, and illustrations in the paper, including supplementary materials.
30+
- [:file\_folder: tables](vignettes/tables): Tables in the paper, including supplementary materials.
31+
32+
## How to Run the Code?
33+
34+
To reproduce the analysis, output, figures, and tables, you will need to clone the repository. To clone the repository, you can do the following from your Terminal:
35+
36+
```bash
37+
git clone https://github.com/Archaeo-Programmer/cropDiffusionR.git
38+
cd cropDiffusionR
39+
```
40+
41+
After installing the `cropDiffusionR` package (via `install_github` as shown above or by using `devtools::install()`), then you can render the analysis, visualizations, and tables.
42+
You can compile the `cropDiffusionR` analysis within R by entering the following in the console:
43+
44+
``` r
45+
rmarkdown::render(here::here('vignettes/Maize_Analysis.Rmd'), output_dir = here::here('vignettes'))
46+
```
47+
48+
If you do not want to compile the R Markdowns, then you can retrieve a readable HTML file by navigating to [Maize_Analysis.html](vignettes/Maize_Analysis.html). Then, click "Raw" and save the file as "Maize_Analysis.html" (i.e., save file with `.html` extension or as HTML file type). Another option, after installing the `cropDiffusionR` package, is to use `rstudioapi::viewer` in the R console:
49+
50+
``` r
51+
rstudioapi::viewer(here::here('vignettes/cropDiffusionR.html'))
52+
```
53+
54+
Another option for reproducing the results is to use the package itself and follow along with the vignette, [ cropDiffusionR](vignettes/cropDiffusionR.Rmd). Data and functions are already loaded into the package.
55+
56+
## Licenses
57+
58+
**Code:** [GNU GPLv3](LICENSE.md)
59+
60+
**Data:** [CC-0](http://creativecommons.org/publicdomain/zero/1.0/)
61+
attribution requested in reuse
62+
63+
## Acknowledgements
64+
65+
This material is based upon work supported by the National Science Foundation under Grants [SMA-1637171](https://www.nsf.gov/awardsearch/showAward?AWD_ID=1637171)
66+
and [SMA-1620462](https://www.nsf.gov/awardsearch/showAward?AWD_ID=1620462), and by the Office of the Chancellor, [Washington State University-Pullman](https://wsu.edu/).

Diff for: cropDiffusionR.Rproj

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Version: 1.0
2+
3+
RestoreWorkspace: Default
4+
SaveWorkspace: Default
5+
AlwaysSaveHistory: Default
6+
7+
EnableCodeIndexing: Yes
8+
UseSpacesForTab: Yes
9+
NumSpacesForTab: 2
10+
Encoding: UTF-8
11+
12+
RnwWeave: Sweave
13+
LaTeX: pdfLaTeX
14+
15+
BuildType: Package
16+
PackageUseDevtools: Yes
17+
PackageInstallArgs: --no-multiarch --with-keep.source
18+
PackageRoxygenize: rd,collate,namespace,vignette

0 commit comments

Comments
 (0)