Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add instructions for contributing and add GitHub workflows #79

Merged
merged 5 commits into from
Apr 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
^LICENSE\.md$
^codecov\.yml$
.travis.yml
^\.github$
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
56 changes: 56 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Workflow derived from https://github.com/r-lib/actions/tree/master/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: R-CMD-check

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: macOS-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'release'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-pandoc@v1

- uses: r-lib/actions/setup-r@v1
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v1
with:
extra-packages: rcmdcheck

- uses: r-lib/actions/check-r-package@v1

- name: Show testthat output
if: always()
run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload check results
if: failure()
uses: actions/upload-artifact@main
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check
30 changes: 30 additions & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Workflow derived from https://github.com/r-lib/actions/tree/master/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: test-coverage

jobs:
test-coverage:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-r@v1
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v1
with:
extra-packages: covr

- name: Test coverage
run: covr::codecov()
shell: Rscript {0}
11 changes: 7 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,17 @@ Imports:
R6,
remotes,
gregorian,
readr,
dplyr
readr
Suggests:
lintr,
covr,
dplyr,
dygraphs,
knitr,
leaflet,
lintr,
rmarkdown,
testthat,
rmarkdown
xts
URL: https://github.com/zizroc/villager/
BugReports: https://github.com/zizroc/villager/issues/
VignetteBuilder: knitr
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# villager
[![Codecov test coverage](https://codecov.io/gh/zizroc/villager/branch/master/graph/badge.svg)](https://codecov.io/gh/zizroc/villager?branch=main)
# dplyr <img src='man/figures/logo.png' align="right" height="139" />

[![R build status](https://github.com/zizroc/villager/workflows/R-CMD-check/badge.svg)](https://github.com/zizroc/villager/actions)
[![Codecov test coverage](https://codecov.io/gh/zizroc/villager/branch/main/graph/badge.svg)](https://codecov.io/gh/zizroc/villager?branch=main)

villager is a framework for creating and running agent based models in R. It's purpose is to provide an extensible framework where modeling can be done in native R.

Expand Down Expand Up @@ -227,3 +230,7 @@ simulator$run_model()
## Advanced Usage

In the examples above, the default properties of agents and resources were used. It's possible that these won't cover all the needs for more diverse models. There are vignettes on extending the agent and resource classes to handle these situations.

## Contributing

Code contributions are welcome as pull requests to the `develop` branch. Bugs, comments, and questions can be submitted as Github Issues.
2 changes: 1 addition & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
comment: true
comment: false

coverage:
status:
Expand Down
Binary file added man/figures/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions vignettes/extending-agents.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ knitr::opts_chunk$set(
```

```{r setup}

library(villager)
library(leaflet)
```
# Extending Agents
To create agents (winiks) that have more properties than the ones provided by _villager_, subclass the `winik` class into a new R6 class. Once sub-classed, additional properties can be added to the winik which can be used in the subsequent model. The new winik class can be tied to individual villages. This gives flexibility to model populations differently when running under the same simulation.
Expand Down Expand Up @@ -144,3 +146,17 @@ los_angeles <- village$new("Test_Village", initial_condition, test_model, gps_wi
simulator <- simulation$new("100-01-01", "100-01-05", list(los_angeles))
simulator$run_model()
```

### Results
```{r}
# Load in data
agent_data <- readr::read_csv("results/Test_Village/winiks.csv")

# Grab just the location data
agent_location <- data.frame(latitude = agent_data$latitude, longitude = agent_data$longitude)

# create a map
leaflet::leaflet() %>%
leaflet::addTiles() %>% # Add default OpenStreetMap map tiles
leaflet::addMarkers (data = agent_location) # Add agent locations
```
29 changes: 29 additions & 0 deletions vignettes/extending-resources.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ knitr::opts_chunk$set(
```

```{r setup}
library(dygraphs)
library(villager)
library(xts)
```

# Extending Resources
Expand Down Expand Up @@ -126,5 +128,32 @@ simulator$run_model()
A timeseries of each resource type is plotted below. The _rice_ resource has clearly not expired while the _corn_ resource has after 10 days.

```{r}
# Load in data
time_series_data <- readr::read_csv("results/Expiring_Resources/resources.csv")

# Get unique dates
unique_dates<- sort(unique(time_series_data$date))

# Get corn & rice quantities and dates
corn_date_quantities <- dplyr::filter(time_series_data, name=="Corn")
rice_date_quantities <- dplyr::filter(time_series_data, name=="Rice")

# create data frame for sorted data
reordered_time_series <- data.frame(Date = unique_dates, Corn = 0, Rice = 0)
for (i in 1:nrow(reordered_time_series)){
reordered_time_series[i,2] = corn_date_quantities[which(corn_date_quantities$date == reordered_time_series$Date[i]),2]
reordered_time_series[i,3] = rice_date_quantities[which(rice_date_quantities$date == reordered_time_series$Date[i]),2]
}

# Convert the date field to an actual date
reordered_time_series$Date <- strptime(reordered_time_series$Date, "%Y-%m-%d")

# Create a xts time series object from the new data frame (an xts object is needed
# for the dygraph plotting library)
final_time_series <- xts::xts(x = reordered_time_series[,-1], order.by = reordered_time_series$Date)

# Plot the graph
dygraphs::dygraph(final_time_series, main = "Crop Quantities", xlab = "Date") %>%
dygraphs::dyAxis("y", label = "Quantity", valueRange = c(0, 25)) %>%
dygraphs::dyOptions(drawGrid = FALSE)
```