Skip to content

Commit

Permalink
Merge pull request CSHS-CWRA#1 from boshek/master
Browse files Browse the repository at this point in the history
Example of adding a function and some added repo materials
  • Loading branch information
KevinShook authored Nov 26, 2017
2 parents b230409 + bcfd9fc commit 5018296
Show file tree
Hide file tree
Showing 17 changed files with 218 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
^.*\.Rproj$
^\.Rproj\.user$
^CONTRIBUTING.md$
^CODE_OF_CONDUCT.md$
.github
8 changes: 8 additions & 0 deletions .github/issue_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!-- If this issue relates to usage of the package, whether a question, bug or similar, along with your query, please paste your devtools::session_info() or sessionInfo() into the code block below, AND include a reproducible example. If this a feature request, please outline the desired functionality and if possible some packages that may help achieve this request. -->

<details> <summary><strong>Session Info</strong></summary>

```r

```
</details>
16 changes: 16 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!--- Provide a general summary of your changes in the Title above -->

## Description
<!--- Describe your changes in detail -->

## Related Issue
<!--- if this closes an issue make sure include e.g., "fix #4"
or similar - or if just relates to an issue make sure to mention
it like "#4" -->

## Example
<!--- if introducing a new feature or changing behavior of existing
methods/functions, include an example if possible to do in brief form -->

<!--- Did you remember to include tests? Unless you're just changing
grammar, please include new tests for your change -->
49 changes: 49 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Contributor Code of Conduct

As contributors and maintainers of this project, and in the interest of
fostering an open and welcoming community, we pledge to respect all people who
contribute through reporting issues, posting feature requests, updating
documentation, submitting pull requests or patches, and other activities.

We are committed to making participation in this project a harassment-free
experience for everyone, regardless of level of experience, gender, gender
identity and expression, sexual orientation, disability, personal appearance,
body size, race, ethnicity, age, religion, or nationality.

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery
* Personal attacks
* Trolling or insulting/derogatory comments
* Public or private harassment
* Publishing other's private information, such as physical or electronic
addresses, without explicit permission
* Other unethical or unprofessional conduct

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

By adopting this Code of Conduct, project maintainers commit themselves to
fairly and consistently applying these principles to every aspect of managing
this project. Project maintainers who do not follow or enforce the Code of
Conduct may be permanently removed from the project team.

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community.

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting a project maintainer at sam.albers@gov.bc.ca. All complaints will be reviewed and investigated
and will result in a response that is deemed necessary and appropriate to the
circumstances. Maintainers are obligated to maintain confidentiality with regard
to the reporter of an incident.


This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 1.3.0, available at
[http://contributor-covenant.org/version/1/3/0/][version]

[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/3/0/
24 changes: 24 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## How to contribute
Anyone interested is encouraged to contribute to the repository by **forking and submitting a pull request**.

(If you are new to GitHub, you might start with a [basic tutorial](https://help.github.com/articles/set-up-git) and check out a more detailed guide to [pull requests](https://help.github.com/articles/using-pull-requests/).)



### Feature request

* Submit an issue on the [Issues page](https://github.com/CSHS-hydRology/CSHShydRology/issues) or;
* Submit a clean pull request with your code contribution for review. Pull requests will be evaluated by the repository guardians on a schedule and if deemed beneficial will be committed to the master.

### Code contributions

* Fork this repo to your Github account
* Clone your version on your account down to your machine from your account, e.g,. `git clone https://github.com/[your username]/CSHShydRology.git`
* Make sure to track progress upstream (i.e., on our version of `CSHShydRology` at `CSHS-hydRology/CSHShydRology`) by doing `git remote add upstream https://github.com/CSHS-hydRology/CSHShydRology.git`. Before making changes make sure to pull changes in from upstream by doing either `git fetch upstream` then merge later or `git pull upstream` to fetch and merge in one step
* Make your changes (bonus points for making changes on a new feature branch)
* Push up to your account
* Submit a pull request to home base (likely master branch, but check to make sure) at `CSHS-hydRology/CSHShydRology`

### Prefer to Email? Email the person listed as maintainer in the `DESCRIPTION` file of this repo.

### Thanks for contributing!
17 changes: 17 additions & 0 deletions CSHShydRology.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX

BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ Version: 0.0.1
Date: 2017-10-11
License: AGPL-3
LazyData: true
URL: https://github.com/CSHS-hydRology/hydRology
URL: https://github.com/CSHS-hydRology/CSHShydRology
RoxygenNote: 6.0.1
Suggests: testthat
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Generated by roxygen2: do not edit by hand

export(wtr_yr)
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# CSHShydRology 0.0.1

* Added a `NEWS.md` file to track changes to the package.
* Added some contributing documentation
* added wtr_yr function



2 changes: 1 addition & 1 deletion R/hydRology-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#' @docType package
#' @name CSHS-hydRology-package
#'
#' @description
#' @description An R package collecting useful functions for hydrologic analysis

#' @references
#' To cite \pkg{CSHS-hydRology} in publications, use the command \code{citation("CSHS-hydRology")} to get the current version of the citation.\cr
Expand Down
25 changes: 25 additions & 0 deletions R/wtr-yr.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#' @title Designation of the water year
#' @description Display water year
#' @export
#'
#' @param dates A vector of dates with actual year
#' @param start_month Month in which the year starts (defaults to October)
#'
#' @return Year starting in start_month
#'
#' @examples
#' date <- seq(as.Date("1910/1/1"), as.Date("1912/1/1"), "days")
#' wtr_yr_date <- wtr_yr(dates=date, start_month=10)
#' data.frame(wtr_yr_date,date)
#' @source http://stackoverflow.com/questions/27626533/r-create-function-to-add-water-year-column

wtr_yr <- function(dates, start_month=10) {
# Convert dates into POSIXlt
dates.posix = as.POSIXlt(dates)
# Year offset
offset = ifelse(dates.posix$mon >= start_month - 1, 1, 0)
# Water year
adj.year = dates.posix$year + 1900 + offset
# Return the water year
adj.year
}
12 changes: 12 additions & 0 deletions man/CSHS-hydRology-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions man/StatisticalHydrology-methods.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 0 additions & 9 deletions man/hydRology-package.Rd

This file was deleted.

27 changes: 27 additions & 0 deletions man/wtr_yr.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
library(testthat)
library(CSHShydRology)

test_check("CSHShydRology")
13 changes: 13 additions & 0 deletions tests/testthat/test_wtr-yr.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
context("Testing wtr-yr")

test_that("wtr_yr correctly categorizes water year", {
month <- 10
date <- seq(as.Date("1910/1/1"), as.Date("1912/1/1"), "days")
wtr_yr <- wtr_yr(dates=date, start_month=month)
comp_df <- data.frame(wtr_yr,date)
expect_true(comp_df[comp_df$date == as.Date("1911-10-01"),]$wtr_yr == 1912)
})




0 comments on commit 5018296

Please sign in to comment.