diff --git a/.Rbuildignore b/.Rbuildignore index 8de87b9..560eece 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -5,3 +5,6 @@ README.Rmd ^_pkgdown\.yml$ ^codecov\.yml$ ^\.travis\.yml$ +^vignettes/* +^CONDUCT\.md$ +^CONTRIBUTING\.md$ diff --git a/.travis.yml b/.travis.yml index 7dea3a1..be87de9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,8 @@ language: r sudo: false cache: packages latex: false +r_packages: + - covr env: global: diff --git a/CONDUCT.md b/CONDUCT.md new file mode 100644 index 0000000..1a8d898 --- /dev/null +++ b/CONDUCT.md @@ -0,0 +1,18 @@ +# R Consortium and the R Community Code of Conduct + +The R Consortium, like the R community as a whole, is made up of members from around the globe with a diverse set of skills, personalities, and experiences. It is through these differences that our community experiences great successes and continued growth. + +Members of the R Consortium and their representatives are bound to follow this R Community Code of Conduct (which is based on the Python Community Code of Conduct). We encourage all members of the R community to likewise follow these guidelines which help steer our interactions and strive to keep R a positive, successful, and growing community. + +# R Community Code of Conduct +A member of the R Community is: + +Open: Members of the community are open to collaboration, whether it's on projects, working groups, packages, problems, or otherwise. We're receptive to constructive comment and criticism, as the experiences and skill sets of other members contribute to the whole of our efforts. We're accepting of anyone who wishes to take part in our activities, fostering an environment where all can participate and everyone can make a difference. + +Considerate: Members of the community are considerate of their peers — other R users. We're thoughtful when addressing the efforts of others, keeping in mind that oftentimes the labor was completed simply for the good of the community. We're attentive in our communications, whether in person or online, and we're tactful when approaching differing views. + +Respectful: Members of the community are respectful. We're respectful of others, their positions, their skills, their commitments, and their efforts. We're respectful of the volunteer efforts that permeate the R community. We're respectful of the processes set forth in the community, and we work within them. When we disagree, we are courteous in raising our issues. + +Overall, we're good to each other. We contribute to this community not because we have to, but because we want to. If we remember that, these guidelines will come naturally. + +Questions/comments/reports? Please write to the Code of Conduct address: conduct@r-consortium.org. (this will email the Board Chair and R Consortium Program manager). Include any available relevant information, including links to any publicly accessible material relating to the matter. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..4aced92 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,37 @@ +# Contributing + +lubridateExtras is an **Open Source** project and there are different ways to contribute. + +Please, use [GitHub issues](https://github.com/ellisvalentiner/lubridateExtras/issues) to **report errors/bugs** or to **ask for new features**. + +Contributions are welcome in the form of **pull requests**. Please follow these guidelines: + +- Write code against the master branch but pull request against the dev branch. +- By making a pull request, you're agreeing to license your code under a [MIT license](https://github.com/ellisvalentiner/lubridateExtras/blob/dev/LICENSE.md). +- Code should be documented and tested. + +## Style + +### Function/variable naming & general syntax + +* Use `snake_case` for function names. + +* Avoid function names that conflict with base packages or other popular ones (e.g. `ggplot2`, `dplyr`, `magrittr`, `data.table`). + +* Use an `object_verb()` naming scheme for functions that take a common data type or interact with a common API. `object` refers to the data/API and `verb` the primary action. This scheme helps avoid namespace conflicts with packages that may have similar verbs, and makes code readable and easy to auto-complete. + +* Functions that manipulate an object/data and return an object/data of the same type, should accept the object/data as the first argument of the function so as to enhance compatibility with the pipe operator (`%>%`) + +### Documentation + +* All exported package functions should be fully documented with examples. + +* When using `roxygen2`, add `#' @noRd` to internal functions. + +### Testing + +* Changes should pass `R CMD check`/`devtools::check()` on all major platforms. + +## Conduct + +We adhere to the [R Consortium and the R Community Code of Conduct](https://wiki.r-consortium.org/view/R_Consortium_and_the_R_Community_Code_of_Conduct). diff --git a/DESCRIPTION b/DESCRIPTION index 70bb1ba..e057049 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: lubridateExtras Type: Package -Title: Convenience functions for the lubridate package -Version: 0.1.0 +Title: Convenience Functions for Manipulating Datetimes +Version: 0.1.1 Authors@R: c( person("Ellis", "Valentiner", email = "ellis.valentiner@gmail.com", role = c("aut", "cre")), person("Geoffrey", "Hannigan", email = "hanni035@umn.edu", role = c("ctb"))) @@ -10,11 +10,18 @@ Description: Provides extra functionality to lubridate. Largely consisting of License: MIT + file LICENSE Encoding: UTF-8 LazyData: true +Depends: + R (>= 3.1.0) Imports: - lubridate (>= 1.6.0) + lubridate (>= 1.6.0), + hms (>= 0.3) Suggests: - knitr + knitr (>= 1.17), + testthat (>= 1.0.2) Remotes: - tidyverse/lubridate + tidyverse/lubridate, + tidyverse/hms, + yihui/knitr, + r-lib/testthat VignetteBuilder: knitr RoxygenNote: 6.0.1 diff --git a/NAMESPACE b/NAMESPACE index cb8c51d..854f059 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,6 +2,7 @@ export(days_ago) export(days_hence) +export(hms) export(is.weekday) export(is.weekend) export(last_month) diff --git a/R/instants.R b/R/instants.R index ac0d75b..83ed67d 100644 --- a/R/instants.R +++ b/R/instants.R @@ -8,9 +8,9 @@ #' #' @examples #' yesterday() -#' yesterday("GMT") +#' yesterday("UTC") yesterday <- function(tzone = "") { - as_date(now(tzone) - days(1)) + as_date(now(tzone = tzone) - days(1)) } #' The next day @@ -23,9 +23,9 @@ yesterday <- function(tzone = "") { #' #' @examples #' tomorrow() -#' tomorrow("GMT") +#' tomorrow("UTC") tomorrow <- function(tzone = "") { - as_date(now(tzone) + days(1)) + as_date(now(tzone = tzone) + days(1)) } #' The date x days ago @@ -120,3 +120,15 @@ is.weekend <- function(x) { is.weekday <- function(x) { wday(x = as_date(x), label = FALSE, abbr = FALSE) %in% 2:6 } + +#' Extract time-of-day values +#' +#' @export hms +#' @param x a POSIXct, POSIXlt, Date, chron, yearmon, yearqtr, zoo, zooreg, +#' timeDate, xts, its, ti, jul, timeSeries, or fts object. +#' @return hms object +#' @examples +#' hms("2017-10-22 15:01:00") +hms <- function(x) { + hms::as.hms(strftime(x, format="%H:%M:%S")) +} diff --git a/README.Rmd b/README.Rmd index 91daa79..62554af 100644 --- a/README.Rmd +++ b/README.Rmd @@ -12,7 +12,11 @@ knitr::opts_chunk$set( comment = "#>", fig.path = "README-" ) -options(tibble.print_min = 5, tibble.print_max = 5) +options( + tibble.print_min = 5, + tibble.print_max = 5 +) +Sys.setenv(TZ = "America/Detroit") ``` # lubridateExtras @@ -48,6 +52,8 @@ tomorrow() days_ago(7) # equivalent to lubridate::today() - lubridate::days(7) days_hence(7) # equivalent to lubridate::today() + lubridate::days(7) + +hms("2017-10-22 15:33:00") # extracts the time-of-day component ``` ## Why lubridateExtras? diff --git a/README.md b/README.md index d5464d4..c69e96b 100644 --- a/README.md +++ b/README.md @@ -30,16 +30,19 @@ Usage library(lubridateExtras) yesterday() -#> [1] "2017-10-11" +#> [1] "2017-10-21" tomorrow() -#> [1] "2017-10-13" +#> [1] "2017-10-23" days_ago(7) # equivalent to lubridate::today() - lubridate::days(7) -#> [1] "2017-10-05" +#> [1] "2017-10-15" days_hence(7) # equivalent to lubridate::today() + lubridate::days(7) -#> [1] "2017-10-19" +#> [1] "2017-10-29" + +hms("2017-10-22 15:33:00") # extracts the time-of-day component +#> 15:33:00 ``` Why lubridateExtras? diff --git a/docs/articles/index.html b/docs/articles/index.html index e5bc482..dfaffd1 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -78,7 +78,7 @@
lubridateExtras provides functions to improve code readability and increase laziness.
-suppressPackageStartupMessages(library(dplyr))
-suppressPackageStartupMessages(library(lubridate))
-library(lubridateExtras)
##
+## Attaching package: 'lubridateExtras'
+## The following object is masked from 'package:lubridate':
+##
+## hms
Suppose you want to review transactions from the past 7 days.
Without lubridateExtras, this might look like this:
+ filter(date >= today() - days(7))Even in this straightforward example it can be difficult to remember: does the >=
operator evaluate before or after the -
operator?
lubridateExtra aims to remove this sort of ambiguity and make the intent clearer through convenience functions. With lubridateExtras, we could rewrite this as follows:
+ filter(date >= days_ago(7))This accomplishes the exact same thing.
library(lubridateExtras)
yesterday()
-#> [1] "2017-10-11"
+#> [1] "2017-10-21"
tomorrow()
-#> [1] "2017-10-13"
+#> [1] "2017-10-23"
days_ago(7) # equivalent to lubridate::today() - lubridate::days(7)
-#> [1] "2017-10-05"
+#> [1] "2017-10-15"
days_hence(7) # equivalent to lubridate::today() + lubridate::days(7)
-#> [1] "2017-10-19"