diff --git a/DESCRIPTION b/DESCRIPTION index 6251b37..7e52679 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: tidier Title: Enhanced 'mutate' -Version: 0.0.1 +Version: 0.1.0 Authors@R: person("Srikanth", "Komala Sheshachala",, diff --git a/NEWS.md b/NEWS.md index a711c9b..996676c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +# tidier 0.1.0 (on github: 2023-06-01) + +* Exposed slider's `.complete` argument in `tidier::mutate` +* bugfix: `mutate` can now modify a column (same name) in sliding operation. + # tidier 0.0.1 * Added a `NEWS.md` file to track changes to the package. diff --git a/R/mutate.R b/R/mutate.R index 687affa..327ee29 100644 --- a/R/mutate.R +++ b/R/mutate.R @@ -47,6 +47,10 @@ #' @param .index (string, optional: Yes) name of index column #' @param .desc (logical_vector, default: FALSE) bool or logical vector of same #' length as `.order_by`. +#' @param .complete (flag, default: FALSE) This will be passed to +#' `slider::slide` / `slider::slide_vec`. Should the function be evaluated on +#' complete windows only? If FALSE, the default, then partial computations +#' will be allowed. #' @return data.frame #' @importFrom magrittr %>% #' @importFrom utils tail @@ -72,37 +76,27 @@ #' # Using a sample airquality dataset, #' # compute mean temp over last seven days in the same month for every row #' +#' set.seed(101) #' airquality %>% #' # create date column -#' dplyr::mutate(date_col = as.Date(paste("1973", -#' stringr::str_pad(Month, -#' width = 2, -#' side = "left", -#' pad = "0" -#' ), -#' stringr::str_pad(Day, -#' width = 2, -#' side = "left", -#' pad = "0" -#' ), -#' sep = "-" -#' ) -#' ) -#' ) %>% +#' dplyr::mutate(date_col = lubridate::make_date(1973, Month, Day)) %>% #' # create gaps by removing some days #' dplyr::slice_sample(prop = 0.8) %>% +#' dplyr::arrange(date_col) %>% #' # compute mean temperature over last seven days in the same month -#' mutate_(avg_temp_over_last_week = mean(Temp, na.rm = TRUE), -#' .order_by = "Day", -#' .by = "Month", -#' .frame = c(lubridate::days(7), # 7 days before current row -#' lubridate::days(-1) # do not include current row -#' ), -#' .index = "date_col" -#' ) +#' tidier::mutate(avg_temp_over_last_week = mean(Temp, na.rm = TRUE), +#' .order_by = "Day", +#' .by = "Month", +#' .frame = c(lubridate::days(7), # 7 days before current row +#' lubridate::days(-1) # do not include current row +#' ), +#' .index = "date_col" +#' ) #' @export -mutate_ = function(x, ..., .by, .order_by, .frame, .index, .desc = FALSE){ +mutate_ = function(x, ..., .by, .order_by, .frame, .index, + .desc = FALSE, .complete = FALSE + ){ # capture expressions -------------------------------------------------------- ddd = rlang::enquos(...) @@ -182,9 +176,11 @@ mutate_ = function(x, ..., .by, .order_by, .frame, .index, .desc = FALSE){ x_copy, .f = ~ as.list(dplyr::summarise(.x, !!!ddd)), .before = .frame[1], - .after = .frame[2] + .after = .frame[2], + .complete = .complete ) ) %>% + remove_common_nested_columns(slide_output__) %>% tidyr::unnest_wider(slide_output__) } else { x_copy = x_copy %>% @@ -194,9 +190,11 @@ mutate_ = function(x, ..., .by, .order_by, .frame, .index, .desc = FALSE){ .f = ~ as.list(dplyr::summarise(.x, !!!ddd)), .i = x_copy[[.index]], .before = .frame[1], - .after = .frame[2] + .after = .frame[2], + .complete = .complete ) ) %>% + remove_common_nested_columns(slide_output__) %>% tidyr::unnest_wider(slide_output__) } } @@ -221,7 +219,8 @@ mutate_ = function(x, ..., .by, .order_by, .frame, .index, .desc = FALSE){ chunk, .f = ~ as.list(dplyr::summarise(.x, !!!ddd)), .before = .frame[1], - .after = .frame[2] + .after = .frame[2], + .complete = .complete ) ) } else { @@ -232,7 +231,8 @@ mutate_ = function(x, ..., .by, .order_by, .frame, .index, .desc = FALSE){ .f = ~ as.list(dplyr::summarise(.x, !!!ddd)), .i = chunk[[.index]], .before = .frame[1], - .after = .frame[2] + .after = .frame[2], + .complete = .complete ) ) } @@ -252,6 +252,7 @@ mutate_ = function(x, ..., .by, .order_by, .frame, .index, .desc = FALSE){ dplyr::ungroup() %>% dplyr::mutate(data__ = furrr::future_map(data__, fun_per_chunk)) %>% tidyr::unnest(data__) %>% + remove_common_nested_columns(slide_output__) %>% tidyr::unnest_wider(slide_output__) } @@ -285,6 +286,7 @@ mutate_ = function(x, ..., .by, .order_by, .frame, .index, .desc = FALSE){ #' API](https://www.databricks.com/blog/2015/07/15/introducing-window-functions-in-spark-sql.html). #' #' +#' #' Implementation Details: #' #' - Iteration per row over the window is implemented using the versatile @@ -309,6 +311,10 @@ mutate_ = function(x, ..., .by, .order_by, .frame, .index, .desc = FALSE){ #' [interval](https://lubridate.tidyverse.org/reference/interval.html) #' objects. See examples. #' @param .index (expression, optional: Yes) index column +#' @param .complete (flag, default: FALSE) This will be passed to +#' `slider::slide` / `slider::slide_vec`. Should the function be evaluated on +#' complete windows only? If FALSE, the default, then partial computations +#' will be allowed. #' @return data.frame #' @importFrom magrittr %>% #' @importFrom utils tail @@ -335,36 +341,24 @@ mutate_ = function(x, ..., .by, .order_by, .frame, .index, .desc = FALSE){ #' # Using a sample airquality dataset, #' # compute mean temp over last seven days in the same month for every row #' +#' set.seed(101) #' airquality %>% #' # create date column -#' dplyr::mutate(date_col = as.Date(paste("1973", -#' stringr::str_pad(Month, -#' width = 2, -#' side = "left", -#' pad = "0" -#' ), -#' stringr::str_pad(Day, -#' width = 2, -#' side = "left", -#' pad = "0" -#' ), -#' sep = "-" -#' ) -#' ) -#' ) %>% +#' dplyr::mutate(date_col = lubridate::make_date(1973, Month, Day)) %>% #' # create gaps by removing some days #' dplyr::slice_sample(prop = 0.8) %>% +#' dplyr::arrange(date_col) %>% #' # compute mean temperature over last seven days in the same month -#' mutate(avg_temp_over_last_week = mean(Temp, na.rm = TRUE), -#' .order_by = Day, -#' .by = Month, -#' .frame = c(lubridate::days(7), # 7 days before current row -#' lubridate::days(-1) # do not include current row -#' ), -#' .index = date_col -#' ) +#' tidier::mutate(avg_temp_over_last_week = mean(Temp, na.rm = TRUE), +#' .order_by = Day, +#' .by = Month, +#' .frame = c(lubridate::days(7), # 7 days before current row +#' lubridate::days(-1) # do not include current row +#' ), +#' .index = date_col +#' ) #' @export -mutate = function(x, ..., .by, .order_by, .frame, .index){ +mutate = function(x, ..., .by, .order_by, .frame, .index, .complete = FALSE){ # capture expressions -------------------------------------------------------- ddd = rlang::enquos(...) @@ -462,9 +456,11 @@ mutate = function(x, ..., .by, .order_by, .frame, .index){ x_copy, .f = ~ as.list(dplyr::summarise(.x, !!!ddd)), .before = .frame[1], - .after = .frame[2] + .after = .frame[2], + .complete = .complete ) ) %>% + remove_common_nested_columns(slide_output__) %>% tidyr::unnest_wider(slide_output__) } else { x_copy = x_copy %>% @@ -474,9 +470,11 @@ mutate = function(x, ..., .by, .order_by, .frame, .index){ .f = ~ as.list(dplyr::summarise(.x, !!!ddd)), .i = x_copy[[.index]], .before = .frame[1], - .after = .frame[2] + .after = .frame[2], + .complete = .complete ) ) %>% + remove_common_nested_columns(slide_output__) %>% tidyr::unnest_wider(slide_output__) } } @@ -499,7 +497,8 @@ mutate = function(x, ..., .by, .order_by, .frame, .index){ chunk, .f = ~ as.list(dplyr::summarise(.x, !!!ddd)), .before = .frame[1], - .after = .frame[2] + .after = .frame[2], + .complete = .complete ) ) } else { @@ -510,7 +509,8 @@ mutate = function(x, ..., .by, .order_by, .frame, .index){ .f = ~ as.list(dplyr::summarise(.x, !!!ddd)), .i = chunk[[.index]], .before = .frame[1], - .after = .frame[2] + .after = .frame[2], + .complete = .complete ) ) } @@ -529,6 +529,7 @@ mutate = function(x, ..., .by, .order_by, .frame, .index){ dplyr::ungroup() %>% dplyr::mutate(data__ = furrr::future_map(data__, fun_per_chunk)) %>% tidyr::unnest(data__) %>% + remove_common_nested_columns(slide_output__) %>% tidyr::unnest_wider(slide_output__) } @@ -542,3 +543,29 @@ mutate = function(x, ..., .by, .order_by, .frame, .index){ return(x_copy) } +# remove_common_nested_columns ---- +#' @name remove_common_nested_columns +#' @title Remove non-list columns when same are present in a list column +#' @description Remove non-list columns when same are present in a list column +#' @param df input dataframe +#' @param list_column Name or expr of the column which is a list of named lists +#' @return dataframe +remove_common_nested_columns = function(df, list_column){ + + # we assume that all dfs in list_column have identical column names + new_names = df %>% + dplyr::slice(1) %>% + dplyr::pull({{ list_column }}) %>% + `[[`(1) %>% + names() + + common_names = intersect(new_names, colnames(df)) + + if (length(common_names) >= 1){ + for (a_common_name in common_names){ + df[[a_common_name]] = NULL + } + } + + return(df) +} diff --git a/README.Rmd b/README.Rmd index 075196c..41ff833 100644 --- a/README.Rmd +++ b/README.Rmd @@ -19,6 +19,8 @@ devtools::load_all() # tidier + +[![CRAN status](https://www.r-pkg.org/badges/version/tidier)](https://CRAN.R-project.org/package=tidier) `tidier` package provides '[Apache Spark](https://spark.apache.org/)' style window aggregation for R dataframes via '[mutate](https://dplyr.tidyverse.org/reference/mutate.html)' in '[dplyr](https://dplyr.tidyverse.org/index.html)' flavour. @@ -37,42 +39,57 @@ airquality |> # compute mean temperature over last seven days in the same month tidier::mutate(avg_temp_over_last_week = mean(Temp, na.rm = TRUE), .order_by = Day, - .by = Month, - .frame = c(lubridate::days(7), # 7 days before current row - lubridate::days(-1) # do not include current row - ), - .index = date_col + .by = Month, + .frame = c(lubridate::days(7), # 7 days before current row + lubridate::days(-1) # do not include current row + ), + .index = date_col ) ``` +## Features + +- `mutate` supports + - `.by` (group by), + - `.order_by` (order by), + - `.frame` (endpoints of window frame), + - `.index` (identify index column like date column), + - `.complete` (whether to compute over incomplete window). + +- `mutate` automatically uses a future backend (via [`furrr`](https://furrr.futureverse.org/)). + ## Motivation This implementation is inspired by Apache Spark's [`windowSpec`](https://spark.apache.org/docs/3.2.1/api/python/reference/api/pyspark.sql.Column.over.html?highlight=windowspec) class with [`rangeBetween`](https://spark.apache.org/docs/3.2.1/api/python/reference/api/pyspark.sql.WindowSpec.rangeBetween.html) and [`rowsBetween`](https://spark.apache.org/docs/3.2.1/api/python/reference/api/pyspark.sql.WindowSpec.rowsBetween.html). ## Ecosystem -1. [`dbplyr`](https://dbplyr.tidyverse.org/) implements this via [`dbplyr::win_over`](https://dbplyr.tidyverse.org/reference/win_over.html?q=win_over#null) enabling [`sparklyr`](https://spark.rstudio.com/) users to write window computations. Also see, [`dbplyr::window_order`/`dbplyr::window_frame`](https://dbplyr.tidyverse.org/reference/window_order.html?q=window_fr#ref-usage). +1. [`dbplyr`](https://dbplyr.tidyverse.org/) implements this via [`dbplyr::win_over`](https://dbplyr.tidyverse.org/reference/win_over.html?q=win_over#null) enabling [`sparklyr`](https://spark.rstudio.com/) users to write window computations. Also see, [`dbplyr::window_order`/`dbplyr::window_frame`](https://dbplyr.tidyverse.org/reference/window_order.html?q=window_fr#ref-usage). -2. [`tidypyspark`](https://talegari.github.io/tidypyspark/_build/html/index.html) python package implements `mutate` style window computation API for pyspark. +2. [`tidypyspark`](https://talegari.github.io/tidypyspark/_build/html/index.html) python package implements `mutate` style window computation API for pyspark. ## Installation -- dev: `remotes::install_github("talegari/tidier")` -- cran: `install.packages("tidier")` +- dev: `remotes::install_github("talegari/tidier")` +- cran: `install.packages("tidier")` ## Acknowledgements `tidier` package is deeply indebted to two amazing packages and people behind it. -1. [`dplyr`](https://cran.r-project.org/package=dplyr): -``` -Wickham H, François R, Henry L, Müller K, Vaughan D (2023). _dplyr: A -Grammar of Data Manipulation_. R package version 1.1.0, -. -``` +1. [`dplyr`](https://cran.r-project.org/package=dplyr): -2. [`slider`](https://cran.r-project.org/package=slider): +```{=html} + ``` -Vaughan D (2021). _slider: Sliding Window Functions_. R package -version 0.2.2, . + Wickham H, François R, Henry L, Müller K, Vaughan D (2023). _dplyr: A + Grammar of Data Manipulation_. R package version 1.1.0, + . + +2. [`slider`](https://cran.r-project.org/package=slider): + +```{=html} + ``` + Vaughan D (2021). _slider: Sliding Window Functions_. R package + version 0.2.2, . diff --git a/README.md b/README.md index 06d6ea7..ed66ce5 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,9 @@ # tidier + +[![CRAN +status](https://www.r-pkg.org/badges/version/tidier)](https://CRAN.R-project.org/package=tidier) `tidier` package provides ‘[Apache Spark](https://spark.apache.org/)’ @@ -26,11 +29,11 @@ airquality |> # compute mean temperature over last seven days in the same month tidier::mutate(avg_temp_over_last_week = mean(Temp, na.rm = TRUE), .order_by = Day, - .by = Month, - .frame = c(lubridate::days(7), # 7 days before current row - lubridate::days(-1) # do not include current row - ), - .index = date_col + .by = Month, + .frame = c(lubridate::days(7), # 7 days before current row + lubridate::days(-1) # do not include current row + ), + .index = date_col ) #> # A tibble: 122 × 8 #> Month Ozone Solar.R Wind Temp Day date_col avg_temp_over_last_week @@ -45,9 +48,20 @@ airquality |> #> 8 6 NA 186 9.2 84 4 1973-06-04 72.5 #> 9 8 78 NA 6.9 86 4 1973-08-04 81.3 #> 10 8 168 238 3.4 81 25 1973-08-25 76.5 -#> # … with 112 more rows +#> # ℹ 112 more rows ``` +## Features + +- `mutate` supports + - `.by` (group by), + - `.order_by` (order by), + - `.frame` (endpoints of window frame), + - `.index` (identify index column like date column), + - `.complete` (whether to compute over incomplete window). +- `mutate` automatically uses a future backend (via + [`furrr`](https://furrr.futureverse.org/)). + ## Motivation This implementation is inspired by Apache Spark’s diff --git a/docs/404.html b/docs/404.html index 90f1aa5..c52ada2 100644 --- a/docs/404.html +++ b/docs/404.html @@ -24,7 +24,7 @@ tidier - 0.0.1 + 0.1.0 + + + + + +
+
+
+ +
+

Remove non-list columns when same are present in a list column

+
+ +
+

Usage

+
remove_common_nested_columns(df, list_column)
+
+ +
+

Arguments

+
df
+

input dataframe

+ + +
list_column
+

Name or expr of the column which is a list of named lists

+ +
+
+

Value

+ + +

dataframe

+
+ +
+ + +
+ + + +
+ + + + + + + diff --git a/docs/search.json b/docs/search.json index eb214bc..2012873 100644 --- a/docs/search.json +++ b/docs/search.json @@ -1 +1 @@ -[{"path":"/LICENSE.html","id":null,"dir":"","previous_headings":"","what":"GNU General Public License","title":"GNU General Public License","text":"Version 3, 29 June 2007Copyright © 2007 Free Software Foundation, Inc.  Everyone permitted copy distribute verbatim copies license document, changing allowed.","code":""},{"path":"/LICENSE.html","id":"preamble","dir":"","previous_headings":"","what":"Preamble","title":"GNU General Public License","text":"GNU General Public License free, copyleft license software kinds works. licenses software practical works designed take away freedom share change works. contrast, GNU General Public License intended guarantee freedom share change versions program–make sure remains free software users. , Free Software Foundation, use GNU General Public License software; applies also work released way authors. can apply programs, . speak free software, referring freedom, price. General Public Licenses designed make sure freedom distribute copies free software (charge wish), receive source code can get want , can change software use pieces new free programs, know can things. protect rights, need prevent others denying rights asking surrender rights. Therefore, certain responsibilities distribute copies software, modify : responsibilities respect freedom others. example, distribute copies program, whether gratis fee, must pass recipients freedoms received. must make sure , , receive can get source code. must show terms know rights. Developers use GNU GPL protect rights two steps: (1) assert copyright software, (2) offer License giving legal permission copy, distribute /modify . developers’ authors’ protection, GPL clearly explains warranty free software. users’ authors’ sake, GPL requires modified versions marked changed, problems attributed erroneously authors previous versions. devices designed deny users access install run modified versions software inside , although manufacturer can . fundamentally incompatible aim protecting users’ freedom change software. systematic pattern abuse occurs area products individuals use, precisely unacceptable. Therefore, designed version GPL prohibit practice products. problems arise substantially domains, stand ready extend provision domains future versions GPL, needed protect freedom users. Finally, every program threatened constantly software patents. States allow patents restrict development use software general-purpose computers, , wish avoid special danger patents applied free program make effectively proprietary. prevent , GPL assures patents used render program non-free. precise terms conditions copying, distribution modification follow.","code":""},{"path":[]},{"path":"/LICENSE.html","id":"id_0-definitions","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"0. Definitions","title":"GNU General Public License","text":"“License” refers version 3 GNU General Public License. “Copyright” also means copyright-like laws apply kinds works, semiconductor masks. “Program” refers copyrightable work licensed License. licensee addressed “”. “Licensees” “recipients” may individuals organizations. “modify” work means copy adapt part work fashion requiring copyright permission, making exact copy. resulting work called “modified version” earlier work work “based ” earlier work. “covered work” means either unmodified Program work based Program. “propagate” work means anything , without permission, make directly secondarily liable infringement applicable copyright law, except executing computer modifying private copy. Propagation includes copying, distribution (without modification), making available public, countries activities well. “convey” work means kind propagation enables parties make receive copies. Mere interaction user computer network, transfer copy, conveying. interactive user interface displays “Appropriate Legal Notices” extent includes convenient prominently visible feature (1) displays appropriate copyright notice, (2) tells user warranty work (except extent warranties provided), licensees may convey work License, view copy License. interface presents list user commands options, menu, prominent item list meets criterion.","code":""},{"path":"/LICENSE.html","id":"id_1-source-code","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"1. Source Code","title":"GNU General Public License","text":"“source code” work means preferred form work making modifications . “Object code” means non-source form work. “Standard Interface” means interface either official standard defined recognized standards body, , case interfaces specified particular programming language, one widely used among developers working language. “System Libraries” executable work include anything, work whole, () included normal form packaging Major Component, part Major Component, (b) serves enable use work Major Component, implement Standard Interface implementation available public source code form. “Major Component”, context, means major essential component (kernel, window system, ) specific operating system () executable work runs, compiler used produce work, object code interpreter used run . “Corresponding Source” work object code form means source code needed generate, install, (executable work) run object code modify work, including scripts control activities. However, include work’s System Libraries, general-purpose tools generally available free programs used unmodified performing activities part work. example, Corresponding Source includes interface definition files associated source files work, source code shared libraries dynamically linked subprograms work specifically designed require, intimate data communication control flow subprograms parts work. Corresponding Source need include anything users can regenerate automatically parts Corresponding Source. Corresponding Source work source code form work.","code":""},{"path":"/LICENSE.html","id":"id_2-basic-permissions","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"2. Basic Permissions","title":"GNU General Public License","text":"rights granted License granted term copyright Program, irrevocable provided stated conditions met. License explicitly affirms unlimited permission run unmodified Program. output running covered work covered License output, given content, constitutes covered work. License acknowledges rights fair use equivalent, provided copyright law. may make, run propagate covered works convey, without conditions long license otherwise remains force. may convey covered works others sole purpose make modifications exclusively , provide facilities running works, provided comply terms License conveying material control copyright. thus making running covered works must exclusively behalf, direction control, terms prohibit making copies copyrighted material outside relationship . Conveying circumstances permitted solely conditions stated . Sublicensing allowed; section 10 makes unnecessary.","code":""},{"path":"/LICENSE.html","id":"id_3-protecting-users-legal-rights-from-anti-circumvention-law","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"3. Protecting Users’ Legal Rights From Anti-Circumvention Law","title":"GNU General Public License","text":"covered work shall deemed part effective technological measure applicable law fulfilling obligations article 11 WIPO copyright treaty adopted 20 December 1996, similar laws prohibiting restricting circumvention measures. convey covered work, waive legal power forbid circumvention technological measures extent circumvention effected exercising rights License respect covered work, disclaim intention limit operation modification work means enforcing, work’s users, third parties’ legal rights forbid circumvention technological measures.","code":""},{"path":"/LICENSE.html","id":"id_4-conveying-verbatim-copies","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"4. Conveying Verbatim Copies","title":"GNU General Public License","text":"may convey verbatim copies Program’s source code receive , medium, provided conspicuously appropriately publish copy appropriate copyright notice; keep intact notices stating License non-permissive terms added accord section 7 apply code; keep intact notices absence warranty; give recipients copy License along Program. may charge price price copy convey, may offer support warranty protection fee.","code":""},{"path":"/LICENSE.html","id":"id_5-conveying-modified-source-versions","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"5. Conveying Modified Source Versions","title":"GNU General Public License","text":"may convey work based Program, modifications produce Program, form source code terms section 4, provided also meet conditions: ) work must carry prominent notices stating modified , giving relevant date. b) work must carry prominent notices stating released License conditions added section 7. requirement modifies requirement section 4 “keep intact notices”. c) must license entire work, whole, License anyone comes possession copy. License therefore apply, along applicable section 7 additional terms, whole work, parts, regardless packaged. License gives permission license work way, invalidate permission separately received . d) work interactive user interfaces, must display Appropriate Legal Notices; however, Program interactive interfaces display Appropriate Legal Notices, work need make . compilation covered work separate independent works, nature extensions covered work, combined form larger program, volume storage distribution medium, called “aggregate” compilation resulting copyright used limit access legal rights compilation’s users beyond individual works permit. Inclusion covered work aggregate cause License apply parts aggregate.","code":""},{"path":"/LICENSE.html","id":"id_6-conveying-non-source-forms","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"6. Conveying Non-Source Forms","title":"GNU General Public License","text":"may convey covered work object code form terms sections 4 5, provided also convey machine-readable Corresponding Source terms License, one ways: ) Convey object code , embodied , physical product (including physical distribution medium), accompanied Corresponding Source fixed durable physical medium customarily used software interchange. b) Convey object code , embodied , physical product (including physical distribution medium), accompanied written offer, valid least three years valid long offer spare parts customer support product model, give anyone possesses object code either (1) copy Corresponding Source software product covered License, durable physical medium customarily used software interchange, price reasonable cost physically performing conveying source, (2) access copy Corresponding Source network server charge. c) Convey individual copies object code copy written offer provide Corresponding Source. alternative allowed occasionally noncommercially, received object code offer, accord subsection 6b. d) Convey object code offering access designated place (gratis charge), offer equivalent access Corresponding Source way place charge. need require recipients copy Corresponding Source along object code. place copy object code network server, Corresponding Source may different server (operated third party) supports equivalent copying facilities, provided maintain clear directions next object code saying find Corresponding Source. Regardless server hosts Corresponding Source, remain obligated ensure available long needed satisfy requirements. e) Convey object code using peer--peer transmission, provided inform peers object code Corresponding Source work offered general public charge subsection 6d. separable portion object code, whose source code excluded Corresponding Source System Library, need included conveying object code work. “User Product” either (1) “consumer product”, means tangible personal property normally used personal, family, household purposes, (2) anything designed sold incorporation dwelling. determining whether product consumer product, doubtful cases shall resolved favor coverage. particular product received particular user, “normally used” refers typical common use class product, regardless status particular user way particular user actually uses, expects expected use, product. product consumer product regardless whether product substantial commercial, industrial non-consumer uses, unless uses represent significant mode use product. “Installation Information” User Product means methods, procedures, authorization keys, information required install execute modified versions covered work User Product modified version Corresponding Source. information must suffice ensure continued functioning modified object code case prevented interfered solely modification made. convey object code work section , , specifically use , User Product, conveying occurs part transaction right possession use User Product transferred recipient perpetuity fixed term (regardless transaction characterized), Corresponding Source conveyed section must accompanied Installation Information. requirement apply neither third party retains ability install modified object code User Product (example, work installed ROM). requirement provide Installation Information include requirement continue provide support service, warranty, updates work modified installed recipient, User Product modified installed. Access network may denied modification materially adversely affects operation network violates rules protocols communication across network. Corresponding Source conveyed, Installation Information provided, accord section must format publicly documented (implementation available public source code form), must require special password key unpacking, reading copying.","code":""},{"path":"/LICENSE.html","id":"id_7-additional-terms","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"7. Additional Terms","title":"GNU General Public License","text":"“Additional permissions” terms supplement terms License making exceptions one conditions. Additional permissions applicable entire Program shall treated though included License, extent valid applicable law. additional permissions apply part Program, part may used separately permissions, entire Program remains governed License without regard additional permissions. convey copy covered work, may option remove additional permissions copy, part . (Additional permissions may written require removal certain cases modify work.) may place additional permissions material, added covered work, can give appropriate copyright permission. Notwithstanding provision License, material add covered work, may (authorized copyright holders material) supplement terms License terms: ) Disclaiming warranty limiting liability differently terms sections 15 16 License; b) Requiring preservation specified reasonable legal notices author attributions material Appropriate Legal Notices displayed works containing ; c) Prohibiting misrepresentation origin material, requiring modified versions material marked reasonable ways different original version; d) Limiting use publicity purposes names licensors authors material; e) Declining grant rights trademark law use trade names, trademarks, service marks; f) Requiring indemnification licensors authors material anyone conveys material (modified versions ) contractual assumptions liability recipient, liability contractual assumptions directly impose licensors authors. non-permissive additional terms considered “restrictions” within meaning section 10. Program received , part , contains notice stating governed License along term restriction, may remove term. license document contains restriction permits relicensing conveying License, may add covered work material governed terms license document, provided restriction survive relicensing conveying. add terms covered work accord section, must place, relevant source files, statement additional terms apply files, notice indicating find applicable terms. Additional terms, permissive non-permissive, may stated form separately written license, stated exceptions; requirements apply either way.","code":""},{"path":"/LICENSE.html","id":"id_8-termination","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"8. Termination","title":"GNU General Public License","text":"may propagate modify covered work except expressly provided License. attempt otherwise propagate modify void, automatically terminate rights License (including patent licenses granted third paragraph section 11). However, cease violation License, license particular copyright holder reinstated () provisionally, unless copyright holder explicitly finally terminates license, (b) permanently, copyright holder fails notify violation reasonable means prior 60 days cessation. Moreover, license particular copyright holder reinstated permanently copyright holder notifies violation reasonable means, first time received notice violation License (work) copyright holder, cure violation prior 30 days receipt notice. Termination rights section terminate licenses parties received copies rights License. rights terminated permanently reinstated, qualify receive new licenses material section 10.","code":""},{"path":"/LICENSE.html","id":"id_9-acceptance-not-required-for-having-copies","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"9. Acceptance Not Required for Having Copies","title":"GNU General Public License","text":"required accept License order receive run copy Program. Ancillary propagation covered work occurring solely consequence using peer--peer transmission receive copy likewise require acceptance. However, nothing License grants permission propagate modify covered work. actions infringe copyright accept License. Therefore, modifying propagating covered work, indicate acceptance License .","code":""},{"path":"/LICENSE.html","id":"id_10-automatic-licensing-of-downstream-recipients","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"10. Automatic Licensing of Downstream Recipients","title":"GNU General Public License","text":"time convey covered work, recipient automatically receives license original licensors, run, modify propagate work, subject License. responsible enforcing compliance third parties License. “entity transaction” transaction transferring control organization, substantially assets one, subdividing organization, merging organizations. propagation covered work results entity transaction, party transaction receives copy work also receives whatever licenses work party’s predecessor interest give previous paragraph, plus right possession Corresponding Source work predecessor interest, predecessor can get reasonable efforts. may impose restrictions exercise rights granted affirmed License. example, may impose license fee, royalty, charge exercise rights granted License, may initiate litigation (including cross-claim counterclaim lawsuit) alleging patent claim infringed making, using, selling, offering sale, importing Program portion .","code":""},{"path":"/LICENSE.html","id":"id_11-patents","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"11. Patents","title":"GNU General Public License","text":"“contributor” copyright holder authorizes use License Program work Program based. work thus licensed called contributor’s “contributor version”. contributor’s “essential patent claims” patent claims owned controlled contributor, whether already acquired hereafter acquired, infringed manner, permitted License, making, using, selling contributor version, include claims infringed consequence modification contributor version. purposes definition, “control” includes right grant patent sublicenses manner consistent requirements License. contributor grants non-exclusive, worldwide, royalty-free patent license contributor’s essential patent claims, make, use, sell, offer sale, import otherwise run, modify propagate contents contributor version. following three paragraphs, “patent license” express agreement commitment, however denominated, enforce patent (express permission practice patent covenant sue patent infringement). “grant” patent license party means make agreement commitment enforce patent party. convey covered work, knowingly relying patent license, Corresponding Source work available anyone copy, free charge terms License, publicly available network server readily accessible means, must either (1) cause Corresponding Source available, (2) arrange deprive benefit patent license particular work, (3) arrange, manner consistent requirements License, extend patent license downstream recipients. “Knowingly relying” means actual knowledge , patent license, conveying covered work country, recipient’s use covered work country, infringe one identifiable patents country reason believe valid. , pursuant connection single transaction arrangement, convey, propagate procuring conveyance , covered work, grant patent license parties receiving covered work authorizing use, propagate, modify convey specific copy covered work, patent license grant automatically extended recipients covered work works based . patent license “discriminatory” include within scope coverage, prohibits exercise , conditioned non-exercise one rights specifically granted License. may convey covered work party arrangement third party business distributing software, make payment third party based extent activity conveying work, third party grants, parties receive covered work , discriminatory patent license () connection copies covered work conveyed (copies made copies), (b) primarily connection specific products compilations contain covered work, unless entered arrangement, patent license granted, prior 28 March 2007. Nothing License shall construed excluding limiting implied license defenses infringement may otherwise available applicable patent law.","code":""},{"path":"/LICENSE.html","id":"id_12-no-surrender-of-others-freedom","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"12. No Surrender of Others’ Freedom","title":"GNU General Public License","text":"conditions imposed (whether court order, agreement otherwise) contradict conditions License, excuse conditions License. convey covered work satisfy simultaneously obligations License pertinent obligations, consequence may convey . example, agree terms obligate collect royalty conveying convey Program, way satisfy terms License refrain entirely conveying Program.","code":""},{"path":"/LICENSE.html","id":"id_13-use-with-the-gnu-affero-general-public-license","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"13. Use with the GNU Affero General Public License","title":"GNU General Public License","text":"Notwithstanding provision License, permission link combine covered work work licensed version 3 GNU Affero General Public License single combined work, convey resulting work. terms License continue apply part covered work, special requirements GNU Affero General Public License, section 13, concerning interaction network apply combination .","code":""},{"path":"/LICENSE.html","id":"id_14-revised-versions-of-this-license","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"14. Revised Versions of this License","title":"GNU General Public License","text":"Free Software Foundation may publish revised /new versions GNU General Public License time time. new versions similar spirit present version, may differ detail address new problems concerns. version given distinguishing version number. Program specifies certain numbered version GNU General Public License “later version” applies , option following terms conditions either numbered version later version published Free Software Foundation. Program specify version number GNU General Public License, may choose version ever published Free Software Foundation. Program specifies proxy can decide future versions GNU General Public License can used, proxy’s public statement acceptance version permanently authorizes choose version Program. Later license versions may give additional different permissions. However, additional obligations imposed author copyright holder result choosing follow later version.","code":""},{"path":"/LICENSE.html","id":"id_15-disclaimer-of-warranty","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"15. Disclaimer of Warranty","title":"GNU General Public License","text":"WARRANTY PROGRAM, EXTENT PERMITTED APPLICABLE LAW. EXCEPT OTHERWISE STATED WRITING COPYRIGHT HOLDERS /PARTIES PROVIDE PROGRAM “” WITHOUT WARRANTY KIND, EITHER EXPRESSED IMPLIED, INCLUDING, LIMITED , IMPLIED WARRANTIES MERCHANTABILITY FITNESS PARTICULAR PURPOSE. ENTIRE RISK QUALITY PERFORMANCE PROGRAM . PROGRAM PROVE DEFECTIVE, ASSUME COST NECESSARY SERVICING, REPAIR CORRECTION.","code":""},{"path":"/LICENSE.html","id":"id_16-limitation-of-liability","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"16. Limitation of Liability","title":"GNU General Public License","text":"EVENT UNLESS REQUIRED APPLICABLE LAW AGREED WRITING COPYRIGHT HOLDER, PARTY MODIFIES /CONVEYS PROGRAM PERMITTED , LIABLE DAMAGES, INCLUDING GENERAL, SPECIAL, INCIDENTAL CONSEQUENTIAL DAMAGES ARISING USE INABILITY USE PROGRAM (INCLUDING LIMITED LOSS DATA DATA RENDERED INACCURATE LOSSES SUSTAINED THIRD PARTIES FAILURE PROGRAM OPERATE PROGRAMS), EVEN HOLDER PARTY ADVISED POSSIBILITY DAMAGES.","code":""},{"path":"/LICENSE.html","id":"id_17-interpretation-of-sections-15-and-16","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"17. Interpretation of Sections 15 and 16","title":"GNU General Public License","text":"disclaimer warranty limitation liability provided given local legal effect according terms, reviewing courts shall apply local law closely approximates absolute waiver civil liability connection Program, unless warranty assumption liability accompanies copy Program return fee. END TERMS CONDITIONS","code":""},{"path":"/LICENSE.html","id":"how-to-apply-these-terms-to-your-new-programs","dir":"","previous_headings":"","what":"How to Apply These Terms to Your New Programs","title":"GNU General Public License","text":"develop new program, want greatest possible use public, best way achieve make free software everyone can redistribute change terms. , attach following notices program. safest attach start source file effectively state exclusion warranty; file least “copyright” line pointer full notice found. Also add information contact electronic paper mail. program terminal interaction, make output short notice like starts interactive mode: hypothetical commands show w show c show appropriate parts General Public License. course, program’s commands might different; GUI interface, use “box”. also get employer (work programmer) school, , sign “copyright disclaimer” program, necessary. information , apply follow GNU GPL, see . GNU General Public License permit incorporating program proprietary programs. program subroutine library, may consider useful permit linking proprietary applications library. want , use GNU Lesser General Public License instead License. first, please read .","code":" Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type 'show w'. This is free software, and you are welcome to redistribute it under certain conditions; type 'show c' for details."},{"path":"/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Srikanth Komala Sheshachala. Author, maintainer.","code":""},{"path":"/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Komala Sheshachala S (2023). tidier: Enhanced 'mutate'. R package version 0.0.1, https://github.com/talegari/tidier.","code":"@Manual{, title = {tidier: Enhanced 'mutate'}, author = {Srikanth {Komala Sheshachala}}, year = {2023}, note = {R package version 0.0.1}, url = {https://github.com/talegari/tidier}, }"},{"path":"/index.html","id":"tidier","dir":"","previous_headings":"","what":"Enhanced mutate","title":"Enhanced mutate","text":"tidier package provides ‘Apache Spark’ style window aggregation R dataframes via ‘mutate’ ‘dplyr’ flavour.","code":""},{"path":"/index.html","id":"example","dir":"","previous_headings":"","what":"Example","title":"Enhanced mutate","text":"Create new column average temp last seven days month.","code":"set.seed(101) air_df = airquality %>% # create date column dplyr::mutate(date_col = as.Date(paste(\"1973\", stringr::str_pad(Month, width = 2, side = \"left\", pad = \"0\" ), stringr::str_pad(Day, width = 2, side = \"left\", pad = \"0\" ), sep = \"-\" ) ) ) %>% # create gaps by removing some days dplyr::slice_sample(prop = 0.8) %>% tibble::as_tibble() air_df #> # A tibble: 122 × 7 #> Ozone Solar.R Wind Temp Month Day date_col #> #> 1 10 264 14.3 73 7 12 1973-07-12 #> 2 NA 127 8 78 6 26 1973-06-26 #> 3 16 77 7.4 82 8 3 1973-08-03 #> 4 14 191 14.3 75 9 28 1973-09-28 #> 5 NA 138 8 83 6 30 1973-06-30 #> 6 NA 98 11.5 80 6 28 1973-06-28 #> 7 122 255 4 89 8 7 1973-08-07 #> 8 47 95 7.4 87 9 5 1973-09-05 #> 9 23 220 10.3 78 9 8 1973-09-08 #> 10 NA 286 8.6 78 6 1 1973-06-01 #> # … with 112 more rows air_df %>% # compute mean temperature over last seven days in the same month mutate(avg_temp_over_last_week = mean(Temp, na.rm = TRUE), .order_by = Day, .by = Month, .frame = c(lubridate::days(7), # 7 days before current row lubridate::days(-1) # do not include current row ), .index = date_col ) #> #> Attaching package: 'purrr' #> The following object is masked from 'package:testthat': #> #> is_null #> The following object is masked from 'package:magrittr': #> #> set_names #> # A tibble: 122 × 8 #> Month Ozone Solar.R Wind Temp Day date_col avg_temp_over_last_week #> #> 1 6 NA 332 13.8 80 14 1973-06-14 87.2 #> 2 5 28 NA 14.9 66 6 1973-05-06 66 #> 3 5 6 78 18.4 57 18 1973-05-18 65.2 #> 4 8 45 212 9.7 79 24 1973-08-24 76.5 #> 5 5 36 118 8 72 2 1973-05-02 NaN #> 6 9 24 238 10.3 68 19 1973-09-19 73 #> 7 9 16 201 8 82 20 1973-09-20 71.7 #> 8 6 NA 186 9.2 84 4 1973-06-04 72.5 #> 9 8 78 NA 6.9 86 4 1973-08-04 81.3 #> 10 8 168 238 3.4 81 25 1973-08-25 76.5 #> # … with 112 more rows"},{"path":"/index.html","id":"motivation","dir":"","previous_headings":"","what":"Motivation","title":"Enhanced mutate","text":"implementation inspired Apache Spark’s windowSpec class rangeBetween rowsBetween.","code":""},{"path":"/index.html","id":"ecosystem","dir":"","previous_headings":"","what":"Ecosystem","title":"Enhanced mutate","text":"dbplyr implements via dbplyr::win_over enabling sparklyr users write window computations. Also see, dbplyr::window_order/dbplyr::window_frame. tidypyspark python package implements mutate style window computation API pyspark.","code":""},{"path":"/index.html","id":"acknowledgements","dir":"","previous_headings":"","what":"Acknowledgements","title":"Enhanced mutate","text":"tidier package deeply indebted two amazing packages people behind . dplyr: Hadley wickham slider: Davis Vaughan","code":""},{"path":"/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"Enhanced mutate","text":"dev: remotes::install_github(\"talegari/tidier\") cran: install.packages(\"tidier\")","code":""},{"path":"/reference/mutate.html","id":null,"dir":"Reference","previous_headings":"","what":"Drop-in replacement for mutate — mutate","title":"Drop-in replacement for mutate — mutate","text":"Provides supercharged version mutate group_by, order_by aggregation arbitrary window frame around row.","code":""},{"path":"/reference/mutate.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Drop-in replacement for mutate — mutate","text":"","code":"mutate(x, ..., .by, .order_by, .frame, .index)"},{"path":"/reference/mutate.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Drop-in replacement for mutate — mutate","text":"x (data.frame) ... expressions passed mutate .(expression, optional: Yes) columns group .order_by (expression, optional: Yes) columns order .frame (vector, optional: Yes) Vector length 2 indicating number rows consider current row. argument .index provided (typically column type date datetime), can interval objects. See examples. .index (expression, optional: Yes) index column","code":""},{"path":"/reference/mutate.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Drop-in replacement for mutate — mutate","text":"data.frame","code":""},{"path":"/reference/mutate.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Drop-in replacement for mutate — mutate","text":"window function returns value every input row dataframe based group rows (frame) neighborhood input row. function implements computation groups (partition_by SQL) predefined order (order_by SQL) across neighborhood rows (frame) defined (, ) /number rows corresponding row /interval objects (ex: c(days(2), days(1))) implementation inspired spark's window API. Implementation Details: Iteration per row window implemented using versatile slider. Application window aggregation can optionally run parallel multiple groups (see argument .) setting future parallel backend. implemented using furrr package. function subsumes regular usecases mutate","code":""},{"path":[]},{"path":"/reference/mutate.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Drop-in replacement for mutate — mutate","text":"","code":"library(\"magrittr\") # example 1 # Using iris dataset, # compute cumulative mean of column `Sepal.Length` # ordered by `Petal.Width` and `Sepal.Width` columns # grouped by `Petal.Length` column iris %>% mutate(sl_mean = mean(Sepal.Length), .order_by = c(Petal.Width, Sepal.Width), .by = Petal.Length, .frame = c(Inf, 0), ) %>% dplyr::slice_min(n = 3, Petal.Width, by = Species) #> #> Attaching package: ‘purrr’ #> The following object is masked from ‘package:magrittr’: #> #> set_names #> # A tibble: 15 × 6 #> Petal.Length Sepal.Length Sepal.Width Petal.Width Species sl_mean #> #> 1 1.1 4.3 3 0.1 setosa 4.3 #> 2 1.4 4.9 3.6 0.1 setosa 4.85 #> 3 1.4 4.8 3 0.1 setosa 4.8 #> 4 1.5 4.9 3.1 0.1 setosa 4.9 #> 5 1.5 5.2 4.1 0.1 setosa 5.05 #> 6 4.1 5.8 2.7 1 versicolor 5.8 #> 7 3.3 5 2.3 1 versicolor 5 #> 8 3.3 4.9 2.4 1 versicolor 4.95 #> 9 3.7 5.5 2.4 1 versicolor 5.5 #> 10 3.5 5 2 1 versicolor 5 #> 11 4 6 2.2 1 versicolor 6 #> 12 3.5 5.7 2.6 1 versicolor 5.35 #> 13 5.6 6.1 2.6 1.4 virginica 6.1 #> 14 5 6 2.2 1.5 virginica 6 #> 15 5.1 6.3 2.8 1.5 virginica 6.3 # example 2 # Using a sample airquality dataset, # compute mean temp over last seven days in the same month for every row airquality %>% # create date column dplyr::mutate(date_col = as.Date(paste(\"1973\", stringr::str_pad(Month, width = 2, side = \"left\", pad = \"0\" ), stringr::str_pad(Day, width = 2, side = \"left\", pad = \"0\" ), sep = \"-\" ) ) ) %>% # create gaps by removing some days dplyr::slice_sample(prop = 0.8) %>% # compute mean temperature over last seven days in the same month mutate(avg_temp_over_last_week = mean(Temp, na.rm = TRUE), .order_by = Day, .by = Month, .frame = c(lubridate::days(7), # 7 days before current row lubridate::days(-1) # do not include current row ), .index = date_col ) #> # A tibble: 122 × 8 #> Month Ozone Solar.R Wind Temp Day date_col avg_temp_over_last_week #> #> 1 9 96 167 6.9 91 1 1973-09-01 NaN #> 2 7 20 81 8.6 82 26 1973-07-26 84.2 #> 3 5 45 252 14.9 81 29 1973-05-29 61.2 #> 4 8 44 190 10.3 78 20 1973-08-20 79 #> 5 8 9 36 14.3 72 22 1973-08-22 78 #> 6 9 46 237 6.9 78 16 1973-09-16 75.6 #> 7 7 77 276 5.1 88 7 1973-07-07 83.2 #> 8 7 NA 258 9.7 81 22 1973-07-22 83.3 #> 9 8 NA 153 5.7 88 27 1973-08-27 78.2 #> 10 8 118 225 2.3 94 29 1973-08-29 80.4 #> # … with 112 more rows"},{"path":"/reference/mutate_.html","id":null,"dir":"Reference","previous_headings":"","what":"Drop-in replacement for mutate — mutate_","title":"Drop-in replacement for mutate — mutate_","text":"Provides supercharged version mutate group_by, order_by aggregation arbitrary window frame around row. function allows arguments passed strings instead expressions.","code":""},{"path":"/reference/mutate_.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Drop-in replacement for mutate — mutate_","text":"","code":"mutate_(x, ..., .by, .order_by, .frame, .index, .desc = FALSE)"},{"path":"/reference/mutate_.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Drop-in replacement for mutate — mutate_","text":"x (data.frame) ... expressions passed mutate .(character vector, optional: Yes) columns group .order_by (character vector, optional: Yes) columns order .frame (vector, optional: Yes) Vector length 2 indicating number rows consider current row. argument .index provided (typically column type date datetime), can interval objects. See examples. .index (string, optional: Yes) name index column .desc (logical_vector, default: FALSE) bool logical vector length .order_by.","code":""},{"path":"/reference/mutate_.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Drop-in replacement for mutate — mutate_","text":"data.frame","code":""},{"path":"/reference/mutate_.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Drop-in replacement for mutate — mutate_","text":"window function returns value every input row dataframe based group rows (frame) neighborhood input row. function implements computation groups (partition_by SQL) predefined order (order_by SQL) across neighborhood rows (frame) defined (, ) /number rows corresponding row /interval objects (ex: c(days(2), days(1))) implementation inspired spark's window API. Implementation Details: Iteration per row window implemented using versatile slider. Application window aggregation can optionally run parallel multiple groups (see argument .) setting future parallel backend. implemented using furrr package. function subsumes regular usecases mutate","code":""},{"path":[]},{"path":"/reference/mutate_.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Drop-in replacement for mutate — mutate_","text":"","code":"library(\"magrittr\") # example 1 # Using iris dataset, # compute cumulative mean of column `Sepal.Length` # ordered by `Petal.Width` and `Sepal.Width` columns # grouped by `Petal.Length` column iris %>% mutate_(sl_mean = mean(Sepal.Length), .order_by = c(\"Petal.Width\", \"Sepal.Width\"), .by = \"Petal.Length\", .frame = c(Inf, 0), ) %>% dplyr::slice_min(n = 3, Petal.Width, by = Species) #> # A tibble: 15 × 6 #> Petal.Length Sepal.Length Sepal.Width Petal.Width Species sl_mean #> #> 1 1.4 4.8 3 0.1 setosa 4.8 #> 2 1.4 4.9 3.6 0.1 setosa 4.85 #> 3 1.1 4.3 3 0.1 setosa 4.3 #> 4 1.5 4.9 3.1 0.1 setosa 4.9 #> 5 1.5 5.2 4.1 0.1 setosa 5.05 #> 6 3.5 5 2 1 versicolor 5 #> 7 3.5 5.7 2.6 1 versicolor 5.35 #> 8 3.3 4.9 2.4 1 versicolor 4.95 #> 9 3.3 5 2.3 1 versicolor 5 #> 10 4.1 5.8 2.7 1 versicolor 5.8 #> 11 4 6 2.2 1 versicolor 6 #> 12 3.7 5.5 2.4 1 versicolor 5.5 #> 13 5.6 6.1 2.6 1.4 virginica 6.1 #> 14 5.1 6.3 2.8 1.5 virginica 6.3 #> 15 5 6 2.2 1.5 virginica 6 # example 2 # Using a sample airquality dataset, # compute mean temp over last seven days in the same month for every row airquality %>% # create date column dplyr::mutate(date_col = as.Date(paste(\"1973\", stringr::str_pad(Month, width = 2, side = \"left\", pad = \"0\" ), stringr::str_pad(Day, width = 2, side = \"left\", pad = \"0\" ), sep = \"-\" ) ) ) %>% # create gaps by removing some days dplyr::slice_sample(prop = 0.8) %>% # compute mean temperature over last seven days in the same month mutate_(avg_temp_over_last_week = mean(Temp, na.rm = TRUE), .order_by = \"Day\", .by = \"Month\", .frame = c(lubridate::days(7), # 7 days before current row lubridate::days(-1) # do not include current row ), .index = \"date_col\" ) #> # A tibble: 122 × 8 #> Month Ozone Solar.R Wind Temp Day date_col avg_temp_over_last_week #> #> 1 5 NA NA 8 57 27 1973-05-27 62.2 #> 2 6 39 323 11.5 87 10 1973-06-10 82 #> 3 7 97 272 5.7 92 9 1973-07-09 85.8 #> 4 6 NA 259 10.9 93 11 1973-06-11 84.9 #> 5 8 44 192 11.5 86 12 1973-08-12 88.8 #> 6 7 82 213 7.4 88 28 1973-07-28 82.3 #> 7 9 24 238 10.3 68 19 1973-09-19 73.8 #> 8 7 108 223 8 85 25 1973-07-25 82.8 #> 9 7 63 220 11.5 85 20 1973-07-20 82.6 #> 10 8 66 NA 4.6 87 6 1973-08-06 83.2 #> # … with 112 more rows"},{"path":"/news/index.html","id":"tidier-001","dir":"Changelog","previous_headings":"","what":"tidier 0.0.1","title":"tidier 0.0.1","text":"Added NEWS.md file track changes package.","code":""}] +[{"path":"/LICENSE.html","id":null,"dir":"","previous_headings":"","what":"GNU General Public License","title":"GNU General Public License","text":"Version 3, 29 June 2007Copyright © 2007 Free Software Foundation, Inc.  Everyone permitted copy distribute verbatim copies license document, changing allowed.","code":""},{"path":"/LICENSE.html","id":"preamble","dir":"","previous_headings":"","what":"Preamble","title":"GNU General Public License","text":"GNU General Public License free, copyleft license software kinds works. licenses software practical works designed take away freedom share change works. contrast, GNU General Public License intended guarantee freedom share change versions program–make sure remains free software users. , Free Software Foundation, use GNU General Public License software; applies also work released way authors. can apply programs, . speak free software, referring freedom, price. General Public Licenses designed make sure freedom distribute copies free software (charge wish), receive source code can get want , can change software use pieces new free programs, know can things. protect rights, need prevent others denying rights asking surrender rights. Therefore, certain responsibilities distribute copies software, modify : responsibilities respect freedom others. example, distribute copies program, whether gratis fee, must pass recipients freedoms received. must make sure , , receive can get source code. must show terms know rights. Developers use GNU GPL protect rights two steps: (1) assert copyright software, (2) offer License giving legal permission copy, distribute /modify . developers’ authors’ protection, GPL clearly explains warranty free software. users’ authors’ sake, GPL requires modified versions marked changed, problems attributed erroneously authors previous versions. devices designed deny users access install run modified versions software inside , although manufacturer can . fundamentally incompatible aim protecting users’ freedom change software. systematic pattern abuse occurs area products individuals use, precisely unacceptable. Therefore, designed version GPL prohibit practice products. problems arise substantially domains, stand ready extend provision domains future versions GPL, needed protect freedom users. Finally, every program threatened constantly software patents. States allow patents restrict development use software general-purpose computers, , wish avoid special danger patents applied free program make effectively proprietary. prevent , GPL assures patents used render program non-free. precise terms conditions copying, distribution modification follow.","code":""},{"path":[]},{"path":"/LICENSE.html","id":"id_0-definitions","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"0. Definitions","title":"GNU General Public License","text":"“License” refers version 3 GNU General Public License. “Copyright” also means copyright-like laws apply kinds works, semiconductor masks. “Program” refers copyrightable work licensed License. licensee addressed “”. “Licensees” “recipients” may individuals organizations. “modify” work means copy adapt part work fashion requiring copyright permission, making exact copy. resulting work called “modified version” earlier work work “based ” earlier work. “covered work” means either unmodified Program work based Program. “propagate” work means anything , without permission, make directly secondarily liable infringement applicable copyright law, except executing computer modifying private copy. Propagation includes copying, distribution (without modification), making available public, countries activities well. “convey” work means kind propagation enables parties make receive copies. Mere interaction user computer network, transfer copy, conveying. interactive user interface displays “Appropriate Legal Notices” extent includes convenient prominently visible feature (1) displays appropriate copyright notice, (2) tells user warranty work (except extent warranties provided), licensees may convey work License, view copy License. interface presents list user commands options, menu, prominent item list meets criterion.","code":""},{"path":"/LICENSE.html","id":"id_1-source-code","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"1. Source Code","title":"GNU General Public License","text":"“source code” work means preferred form work making modifications . “Object code” means non-source form work. “Standard Interface” means interface either official standard defined recognized standards body, , case interfaces specified particular programming language, one widely used among developers working language. “System Libraries” executable work include anything, work whole, () included normal form packaging Major Component, part Major Component, (b) serves enable use work Major Component, implement Standard Interface implementation available public source code form. “Major Component”, context, means major essential component (kernel, window system, ) specific operating system () executable work runs, compiler used produce work, object code interpreter used run . “Corresponding Source” work object code form means source code needed generate, install, (executable work) run object code modify work, including scripts control activities. However, include work’s System Libraries, general-purpose tools generally available free programs used unmodified performing activities part work. example, Corresponding Source includes interface definition files associated source files work, source code shared libraries dynamically linked subprograms work specifically designed require, intimate data communication control flow subprograms parts work. Corresponding Source need include anything users can regenerate automatically parts Corresponding Source. Corresponding Source work source code form work.","code":""},{"path":"/LICENSE.html","id":"id_2-basic-permissions","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"2. Basic Permissions","title":"GNU General Public License","text":"rights granted License granted term copyright Program, irrevocable provided stated conditions met. License explicitly affirms unlimited permission run unmodified Program. output running covered work covered License output, given content, constitutes covered work. License acknowledges rights fair use equivalent, provided copyright law. may make, run propagate covered works convey, without conditions long license otherwise remains force. may convey covered works others sole purpose make modifications exclusively , provide facilities running works, provided comply terms License conveying material control copyright. thus making running covered works must exclusively behalf, direction control, terms prohibit making copies copyrighted material outside relationship . Conveying circumstances permitted solely conditions stated . Sublicensing allowed; section 10 makes unnecessary.","code":""},{"path":"/LICENSE.html","id":"id_3-protecting-users-legal-rights-from-anti-circumvention-law","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"3. Protecting Users’ Legal Rights From Anti-Circumvention Law","title":"GNU General Public License","text":"covered work shall deemed part effective technological measure applicable law fulfilling obligations article 11 WIPO copyright treaty adopted 20 December 1996, similar laws prohibiting restricting circumvention measures. convey covered work, waive legal power forbid circumvention technological measures extent circumvention effected exercising rights License respect covered work, disclaim intention limit operation modification work means enforcing, work’s users, third parties’ legal rights forbid circumvention technological measures.","code":""},{"path":"/LICENSE.html","id":"id_4-conveying-verbatim-copies","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"4. Conveying Verbatim Copies","title":"GNU General Public License","text":"may convey verbatim copies Program’s source code receive , medium, provided conspicuously appropriately publish copy appropriate copyright notice; keep intact notices stating License non-permissive terms added accord section 7 apply code; keep intact notices absence warranty; give recipients copy License along Program. may charge price price copy convey, may offer support warranty protection fee.","code":""},{"path":"/LICENSE.html","id":"id_5-conveying-modified-source-versions","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"5. Conveying Modified Source Versions","title":"GNU General Public License","text":"may convey work based Program, modifications produce Program, form source code terms section 4, provided also meet conditions: ) work must carry prominent notices stating modified , giving relevant date. b) work must carry prominent notices stating released License conditions added section 7. requirement modifies requirement section 4 “keep intact notices”. c) must license entire work, whole, License anyone comes possession copy. License therefore apply, along applicable section 7 additional terms, whole work, parts, regardless packaged. License gives permission license work way, invalidate permission separately received . d) work interactive user interfaces, must display Appropriate Legal Notices; however, Program interactive interfaces display Appropriate Legal Notices, work need make . compilation covered work separate independent works, nature extensions covered work, combined form larger program, volume storage distribution medium, called “aggregate” compilation resulting copyright used limit access legal rights compilation’s users beyond individual works permit. Inclusion covered work aggregate cause License apply parts aggregate.","code":""},{"path":"/LICENSE.html","id":"id_6-conveying-non-source-forms","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"6. Conveying Non-Source Forms","title":"GNU General Public License","text":"may convey covered work object code form terms sections 4 5, provided also convey machine-readable Corresponding Source terms License, one ways: ) Convey object code , embodied , physical product (including physical distribution medium), accompanied Corresponding Source fixed durable physical medium customarily used software interchange. b) Convey object code , embodied , physical product (including physical distribution medium), accompanied written offer, valid least three years valid long offer spare parts customer support product model, give anyone possesses object code either (1) copy Corresponding Source software product covered License, durable physical medium customarily used software interchange, price reasonable cost physically performing conveying source, (2) access copy Corresponding Source network server charge. c) Convey individual copies object code copy written offer provide Corresponding Source. alternative allowed occasionally noncommercially, received object code offer, accord subsection 6b. d) Convey object code offering access designated place (gratis charge), offer equivalent access Corresponding Source way place charge. need require recipients copy Corresponding Source along object code. place copy object code network server, Corresponding Source may different server (operated third party) supports equivalent copying facilities, provided maintain clear directions next object code saying find Corresponding Source. Regardless server hosts Corresponding Source, remain obligated ensure available long needed satisfy requirements. e) Convey object code using peer--peer transmission, provided inform peers object code Corresponding Source work offered general public charge subsection 6d. separable portion object code, whose source code excluded Corresponding Source System Library, need included conveying object code work. “User Product” either (1) “consumer product”, means tangible personal property normally used personal, family, household purposes, (2) anything designed sold incorporation dwelling. determining whether product consumer product, doubtful cases shall resolved favor coverage. particular product received particular user, “normally used” refers typical common use class product, regardless status particular user way particular user actually uses, expects expected use, product. product consumer product regardless whether product substantial commercial, industrial non-consumer uses, unless uses represent significant mode use product. “Installation Information” User Product means methods, procedures, authorization keys, information required install execute modified versions covered work User Product modified version Corresponding Source. information must suffice ensure continued functioning modified object code case prevented interfered solely modification made. convey object code work section , , specifically use , User Product, conveying occurs part transaction right possession use User Product transferred recipient perpetuity fixed term (regardless transaction characterized), Corresponding Source conveyed section must accompanied Installation Information. requirement apply neither third party retains ability install modified object code User Product (example, work installed ROM). requirement provide Installation Information include requirement continue provide support service, warranty, updates work modified installed recipient, User Product modified installed. Access network may denied modification materially adversely affects operation network violates rules protocols communication across network. Corresponding Source conveyed, Installation Information provided, accord section must format publicly documented (implementation available public source code form), must require special password key unpacking, reading copying.","code":""},{"path":"/LICENSE.html","id":"id_7-additional-terms","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"7. Additional Terms","title":"GNU General Public License","text":"“Additional permissions” terms supplement terms License making exceptions one conditions. Additional permissions applicable entire Program shall treated though included License, extent valid applicable law. additional permissions apply part Program, part may used separately permissions, entire Program remains governed License without regard additional permissions. convey copy covered work, may option remove additional permissions copy, part . (Additional permissions may written require removal certain cases modify work.) may place additional permissions material, added covered work, can give appropriate copyright permission. Notwithstanding provision License, material add covered work, may (authorized copyright holders material) supplement terms License terms: ) Disclaiming warranty limiting liability differently terms sections 15 16 License; b) Requiring preservation specified reasonable legal notices author attributions material Appropriate Legal Notices displayed works containing ; c) Prohibiting misrepresentation origin material, requiring modified versions material marked reasonable ways different original version; d) Limiting use publicity purposes names licensors authors material; e) Declining grant rights trademark law use trade names, trademarks, service marks; f) Requiring indemnification licensors authors material anyone conveys material (modified versions ) contractual assumptions liability recipient, liability contractual assumptions directly impose licensors authors. non-permissive additional terms considered “restrictions” within meaning section 10. Program received , part , contains notice stating governed License along term restriction, may remove term. license document contains restriction permits relicensing conveying License, may add covered work material governed terms license document, provided restriction survive relicensing conveying. add terms covered work accord section, must place, relevant source files, statement additional terms apply files, notice indicating find applicable terms. Additional terms, permissive non-permissive, may stated form separately written license, stated exceptions; requirements apply either way.","code":""},{"path":"/LICENSE.html","id":"id_8-termination","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"8. Termination","title":"GNU General Public License","text":"may propagate modify covered work except expressly provided License. attempt otherwise propagate modify void, automatically terminate rights License (including patent licenses granted third paragraph section 11). However, cease violation License, license particular copyright holder reinstated () provisionally, unless copyright holder explicitly finally terminates license, (b) permanently, copyright holder fails notify violation reasonable means prior 60 days cessation. Moreover, license particular copyright holder reinstated permanently copyright holder notifies violation reasonable means, first time received notice violation License (work) copyright holder, cure violation prior 30 days receipt notice. Termination rights section terminate licenses parties received copies rights License. rights terminated permanently reinstated, qualify receive new licenses material section 10.","code":""},{"path":"/LICENSE.html","id":"id_9-acceptance-not-required-for-having-copies","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"9. Acceptance Not Required for Having Copies","title":"GNU General Public License","text":"required accept License order receive run copy Program. Ancillary propagation covered work occurring solely consequence using peer--peer transmission receive copy likewise require acceptance. However, nothing License grants permission propagate modify covered work. actions infringe copyright accept License. Therefore, modifying propagating covered work, indicate acceptance License .","code":""},{"path":"/LICENSE.html","id":"id_10-automatic-licensing-of-downstream-recipients","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"10. Automatic Licensing of Downstream Recipients","title":"GNU General Public License","text":"time convey covered work, recipient automatically receives license original licensors, run, modify propagate work, subject License. responsible enforcing compliance third parties License. “entity transaction” transaction transferring control organization, substantially assets one, subdividing organization, merging organizations. propagation covered work results entity transaction, party transaction receives copy work also receives whatever licenses work party’s predecessor interest give previous paragraph, plus right possession Corresponding Source work predecessor interest, predecessor can get reasonable efforts. may impose restrictions exercise rights granted affirmed License. example, may impose license fee, royalty, charge exercise rights granted License, may initiate litigation (including cross-claim counterclaim lawsuit) alleging patent claim infringed making, using, selling, offering sale, importing Program portion .","code":""},{"path":"/LICENSE.html","id":"id_11-patents","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"11. Patents","title":"GNU General Public License","text":"“contributor” copyright holder authorizes use License Program work Program based. work thus licensed called contributor’s “contributor version”. contributor’s “essential patent claims” patent claims owned controlled contributor, whether already acquired hereafter acquired, infringed manner, permitted License, making, using, selling contributor version, include claims infringed consequence modification contributor version. purposes definition, “control” includes right grant patent sublicenses manner consistent requirements License. contributor grants non-exclusive, worldwide, royalty-free patent license contributor’s essential patent claims, make, use, sell, offer sale, import otherwise run, modify propagate contents contributor version. following three paragraphs, “patent license” express agreement commitment, however denominated, enforce patent (express permission practice patent covenant sue patent infringement). “grant” patent license party means make agreement commitment enforce patent party. convey covered work, knowingly relying patent license, Corresponding Source work available anyone copy, free charge terms License, publicly available network server readily accessible means, must either (1) cause Corresponding Source available, (2) arrange deprive benefit patent license particular work, (3) arrange, manner consistent requirements License, extend patent license downstream recipients. “Knowingly relying” means actual knowledge , patent license, conveying covered work country, recipient’s use covered work country, infringe one identifiable patents country reason believe valid. , pursuant connection single transaction arrangement, convey, propagate procuring conveyance , covered work, grant patent license parties receiving covered work authorizing use, propagate, modify convey specific copy covered work, patent license grant automatically extended recipients covered work works based . patent license “discriminatory” include within scope coverage, prohibits exercise , conditioned non-exercise one rights specifically granted License. may convey covered work party arrangement third party business distributing software, make payment third party based extent activity conveying work, third party grants, parties receive covered work , discriminatory patent license () connection copies covered work conveyed (copies made copies), (b) primarily connection specific products compilations contain covered work, unless entered arrangement, patent license granted, prior 28 March 2007. Nothing License shall construed excluding limiting implied license defenses infringement may otherwise available applicable patent law.","code":""},{"path":"/LICENSE.html","id":"id_12-no-surrender-of-others-freedom","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"12. No Surrender of Others’ Freedom","title":"GNU General Public License","text":"conditions imposed (whether court order, agreement otherwise) contradict conditions License, excuse conditions License. convey covered work satisfy simultaneously obligations License pertinent obligations, consequence may convey . example, agree terms obligate collect royalty conveying convey Program, way satisfy terms License refrain entirely conveying Program.","code":""},{"path":"/LICENSE.html","id":"id_13-use-with-the-gnu-affero-general-public-license","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"13. Use with the GNU Affero General Public License","title":"GNU General Public License","text":"Notwithstanding provision License, permission link combine covered work work licensed version 3 GNU Affero General Public License single combined work, convey resulting work. terms License continue apply part covered work, special requirements GNU Affero General Public License, section 13, concerning interaction network apply combination .","code":""},{"path":"/LICENSE.html","id":"id_14-revised-versions-of-this-license","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"14. Revised Versions of this License","title":"GNU General Public License","text":"Free Software Foundation may publish revised /new versions GNU General Public License time time. new versions similar spirit present version, may differ detail address new problems concerns. version given distinguishing version number. Program specifies certain numbered version GNU General Public License “later version” applies , option following terms conditions either numbered version later version published Free Software Foundation. Program specify version number GNU General Public License, may choose version ever published Free Software Foundation. Program specifies proxy can decide future versions GNU General Public License can used, proxy’s public statement acceptance version permanently authorizes choose version Program. Later license versions may give additional different permissions. However, additional obligations imposed author copyright holder result choosing follow later version.","code":""},{"path":"/LICENSE.html","id":"id_15-disclaimer-of-warranty","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"15. Disclaimer of Warranty","title":"GNU General Public License","text":"WARRANTY PROGRAM, EXTENT PERMITTED APPLICABLE LAW. EXCEPT OTHERWISE STATED WRITING COPYRIGHT HOLDERS /PARTIES PROVIDE PROGRAM “” WITHOUT WARRANTY KIND, EITHER EXPRESSED IMPLIED, INCLUDING, LIMITED , IMPLIED WARRANTIES MERCHANTABILITY FITNESS PARTICULAR PURPOSE. ENTIRE RISK QUALITY PERFORMANCE PROGRAM . PROGRAM PROVE DEFECTIVE, ASSUME COST NECESSARY SERVICING, REPAIR CORRECTION.","code":""},{"path":"/LICENSE.html","id":"id_16-limitation-of-liability","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"16. Limitation of Liability","title":"GNU General Public License","text":"EVENT UNLESS REQUIRED APPLICABLE LAW AGREED WRITING COPYRIGHT HOLDER, PARTY MODIFIES /CONVEYS PROGRAM PERMITTED , LIABLE DAMAGES, INCLUDING GENERAL, SPECIAL, INCIDENTAL CONSEQUENTIAL DAMAGES ARISING USE INABILITY USE PROGRAM (INCLUDING LIMITED LOSS DATA DATA RENDERED INACCURATE LOSSES SUSTAINED THIRD PARTIES FAILURE PROGRAM OPERATE PROGRAMS), EVEN HOLDER PARTY ADVISED POSSIBILITY DAMAGES.","code":""},{"path":"/LICENSE.html","id":"id_17-interpretation-of-sections-15-and-16","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"17. Interpretation of Sections 15 and 16","title":"GNU General Public License","text":"disclaimer warranty limitation liability provided given local legal effect according terms, reviewing courts shall apply local law closely approximates absolute waiver civil liability connection Program, unless warranty assumption liability accompanies copy Program return fee. END TERMS CONDITIONS","code":""},{"path":"/LICENSE.html","id":"how-to-apply-these-terms-to-your-new-programs","dir":"","previous_headings":"","what":"How to Apply These Terms to Your New Programs","title":"GNU General Public License","text":"develop new program, want greatest possible use public, best way achieve make free software everyone can redistribute change terms. , attach following notices program. safest attach start source file effectively state exclusion warranty; file least “copyright” line pointer full notice found. Also add information contact electronic paper mail. program terminal interaction, make output short notice like starts interactive mode: hypothetical commands show w show c show appropriate parts General Public License. course, program’s commands might different; GUI interface, use “box”. also get employer (work programmer) school, , sign “copyright disclaimer” program, necessary. information , apply follow GNU GPL, see . GNU General Public License permit incorporating program proprietary programs. program subroutine library, may consider useful permit linking proprietary applications library. want , use GNU Lesser General Public License instead License. first, please read .","code":" Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type 'show w'. This is free software, and you are welcome to redistribute it under certain conditions; type 'show c' for details."},{"path":"/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Srikanth Komala Sheshachala. Author, maintainer.","code":""},{"path":"/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Srikanth Komala Sheshachala (2023). tidier: Enhanced 'mutate'. Provides ‘Apache Spark’ style window aggregation R dataframes via ‘mutate’ ‘dplyr’ flavour. R package version 4.2.0. https://CRAN.R-project.org/package=tidier","code":"@Manual{, title = {tidier: Enhanced 'mutate'}, author = {Srikanth Komala Sheshachala}, year = {2023}, url = {https://CRAN.R-project.org/package=tidier}, }"},{"path":"/index.html","id":"tidier","dir":"","previous_headings":"","what":"Enhanced mutate","title":"Enhanced mutate","text":"tidier package provides ‘Apache Spark’ style window aggregation R dataframes via ‘mutate’ ‘dplyr’ flavour.","code":""},{"path":"/index.html","id":"example","dir":"","previous_headings":"","what":"Example","title":"Enhanced mutate","text":"Create new column average temp last seven days month.","code":"set.seed(101) airquality |> # create date column dplyr::mutate(date_col = lubridate::make_date(1973, Month, Day)) |> # create gaps by removing some days dplyr::slice_sample(prop = 0.8) |> # compute mean temperature over last seven days in the same month tidier::mutate(avg_temp_over_last_week = mean(Temp, na.rm = TRUE), .order_by = Day, .by = Month, .frame = c(lubridate::days(7), # 7 days before current row lubridate::days(-1) # do not include current row ), .index = date_col ) #> # A tibble: 122 × 8 #> Month Ozone Solar.R Wind Temp Day date_col avg_temp_over_last_week #> #> 1 6 NA 332 13.8 80 14 1973-06-14 87.2 #> 2 5 28 NA 14.9 66 6 1973-05-06 66 #> 3 5 6 78 18.4 57 18 1973-05-18 65.2 #> 4 8 45 212 9.7 79 24 1973-08-24 76.5 #> 5 5 36 118 8 72 2 1973-05-02 NaN #> 6 9 24 238 10.3 68 19 1973-09-19 73 #> 7 9 16 201 8 82 20 1973-09-20 71.7 #> 8 6 NA 186 9.2 84 4 1973-06-04 72.5 #> 9 8 78 NA 6.9 86 4 1973-08-04 81.3 #> 10 8 168 238 3.4 81 25 1973-08-25 76.5 #> # ℹ 112 more rows"},{"path":"/index.html","id":"features","dir":"","previous_headings":"","what":"Features","title":"Enhanced mutate","text":".(group ), .order_by (order ), .frame (endpoints window frame), .index (identify index column like date column), .complete (whether compute incomplete window). mutate automatically uses future backend (via furrr).","code":""},{"path":"/index.html","id":"motivation","dir":"","previous_headings":"","what":"Motivation","title":"Enhanced mutate","text":"implementation inspired Apache Spark’s windowSpec class rangeBetween rowsBetween.","code":""},{"path":"/index.html","id":"ecosystem","dir":"","previous_headings":"","what":"Ecosystem","title":"Enhanced mutate","text":"dbplyr implements via dbplyr::win_over enabling sparklyr users write window computations. Also see, dbplyr::window_order/dbplyr::window_frame. tidypyspark python package implements mutate style window computation API pyspark.","code":""},{"path":"/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"Enhanced mutate","text":"dev: remotes::install_github(\"talegari/tidier\") cran: install.packages(\"tidier\")","code":""},{"path":"/index.html","id":"acknowledgements","dir":"","previous_headings":"","what":"Acknowledgements","title":"Enhanced mutate","text":"tidier package deeply indebted two amazing packages people behind . dplyr: slider:","code":"Wickham H, François R, Henry L, Müller K, Vaughan D (2023). _dplyr: A Grammar of Data Manipulation_. R package version 1.1.0, . Vaughan D (2021). _slider: Sliding Window Functions_. R package version 0.2.2, ."},{"path":"/reference/mutate.html","id":null,"dir":"Reference","previous_headings":"","what":"Drop-in replacement for mutate — mutate","title":"Drop-in replacement for mutate — mutate","text":"Provides supercharged version mutate group_by, order_by aggregation arbitrary window frame around row.","code":""},{"path":"/reference/mutate.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Drop-in replacement for mutate — mutate","text":"","code":"mutate(x, ..., .by, .order_by, .frame, .index, .complete = FALSE)"},{"path":"/reference/mutate.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Drop-in replacement for mutate — mutate","text":"x (data.frame) ... expressions passed mutate .(expression, optional: Yes) columns group .order_by (expression, optional: Yes) columns order .frame (vector, optional: Yes) Vector length 2 indicating number rows consider current row. argument .index provided (typically column type date datetime), can interval objects. See examples. .index (expression, optional: Yes) index column .complete (flag, default: FALSE) passed slider::slide / slider::slide_vec. function evaluated complete windows ? FALSE, default, partial computations allowed.","code":""},{"path":"/reference/mutate.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Drop-in replacement for mutate — mutate","text":"data.frame","code":""},{"path":"/reference/mutate.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Drop-in replacement for mutate — mutate","text":"window function returns value every input row dataframe based group rows (frame) neighborhood input row. function implements computation groups (partition_by SQL) predefined order (order_by SQL) across neighborhood rows (frame) defined (, ) /number rows corresponding row /interval objects (ex: c(days(2), days(1))) implementation inspired spark's window API. Implementation Details: Iteration per row window implemented using versatile slider. Application window aggregation can optionally run parallel multiple groups (see argument .) setting future parallel backend. implemented using furrr package. function subsumes regular usecases mutate","code":""},{"path":[]},{"path":"/reference/mutate.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Drop-in replacement for mutate — mutate","text":"","code":"library(\"magrittr\") # example 1 # Using iris dataset, # compute cumulative mean of column `Sepal.Length` # ordered by `Petal.Width` and `Sepal.Width` columns # grouped by `Petal.Length` column iris %>% mutate(sl_mean = mean(Sepal.Length), .order_by = c(Petal.Width, Sepal.Width), .by = Petal.Length, .frame = c(Inf, 0), ) %>% dplyr::slice_min(n = 3, Petal.Width, by = Species) #> #> Attaching package: ‘purrr’ #> The following object is masked from ‘package:magrittr’: #> #> set_names #> # A tibble: 15 × 6 #> Petal.Length Sepal.Length Sepal.Width Petal.Width Species sl_mean #> #> 1 1.1 4.3 3 0.1 setosa 4.3 #> 2 1.4 4.9 3.6 0.1 setosa 4.85 #> 3 1.4 4.8 3 0.1 setosa 4.8 #> 4 1.5 4.9 3.1 0.1 setosa 4.9 #> 5 1.5 5.2 4.1 0.1 setosa 5.05 #> 6 4.1 5.8 2.7 1 versicolor 5.8 #> 7 3.3 5 2.3 1 versicolor 5 #> 8 3.3 4.9 2.4 1 versicolor 4.95 #> 9 3.7 5.5 2.4 1 versicolor 5.5 #> 10 3.5 5 2 1 versicolor 5 #> 11 4 6 2.2 1 versicolor 6 #> 12 3.5 5.7 2.6 1 versicolor 5.35 #> 13 5.6 6.1 2.6 1.4 virginica 6.1 #> 14 5 6 2.2 1.5 virginica 6 #> 15 5.1 6.3 2.8 1.5 virginica 6.3 # example 2 # Using a sample airquality dataset, # compute mean temp over last seven days in the same month for every row set.seed(101) airquality %>% # create date column dplyr::mutate(date_col = lubridate::make_date(1973, Month, Day)) %>% # create gaps by removing some days dplyr::slice_sample(prop = 0.8) %>% dplyr::arrange(date_col) %>% # compute mean temperature over last seven days in the same month tidier::mutate(avg_temp_over_last_week = mean(Temp, na.rm = TRUE), .order_by = Day, .by = Month, .frame = c(lubridate::days(7), # 7 days before current row lubridate::days(-1) # do not include current row ), .index = date_col ) #> # A tibble: 122 × 8 #> Month Ozone Solar.R Wind Temp Day date_col avg_temp_over_last_week #> #> 1 7 64 175 4.6 83 5 1973-07-05 83.5 #> 2 8 16 77 7.4 82 3 1973-08-03 81 #> 3 5 36 118 8 72 2 1973-05-02 NaN #> 4 6 NA 286 8.6 78 1 1973-06-01 NaN #> 5 8 78 NA 6.9 86 4 1973-08-04 81.3 #> 6 5 12 149 12.6 74 3 1973-05-03 72 #> 7 9 78 197 5.1 92 2 1973-09-02 NaN #> 8 6 NA 242 16.1 67 3 1973-06-03 78 #> 9 7 77 276 5.1 88 7 1973-07-07 83.4 #> 10 8 35 NA 7.4 85 5 1973-08-05 82.5 #> # ℹ 112 more rows"},{"path":"/reference/mutate_.html","id":null,"dir":"Reference","previous_headings":"","what":"Drop-in replacement for mutate — mutate_","title":"Drop-in replacement for mutate — mutate_","text":"Provides supercharged version mutate group_by, order_by aggregation arbitrary window frame around row. function allows arguments passed strings instead expressions.","code":""},{"path":"/reference/mutate_.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Drop-in replacement for mutate — mutate_","text":"","code":"mutate_( x, ..., .by, .order_by, .frame, .index, .desc = FALSE, .complete = FALSE )"},{"path":"/reference/mutate_.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Drop-in replacement for mutate — mutate_","text":"x (data.frame) ... expressions passed mutate .(character vector, optional: Yes) columns group .order_by (character vector, optional: Yes) columns order .frame (vector, optional: Yes) Vector length 2 indicating number rows consider current row. argument .index provided (typically column type date datetime), can interval objects. See examples. .index (string, optional: Yes) name index column .desc (logical_vector, default: FALSE) bool logical vector length .order_by. .complete (flag, default: FALSE) passed slider::slide / slider::slide_vec. function evaluated complete windows ? FALSE, default, partial computations allowed.","code":""},{"path":"/reference/mutate_.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Drop-in replacement for mutate — mutate_","text":"data.frame","code":""},{"path":"/reference/mutate_.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Drop-in replacement for mutate — mutate_","text":"window function returns value every input row dataframe based group rows (frame) neighborhood input row. function implements computation groups (partition_by SQL) predefined order (order_by SQL) across neighborhood rows (frame) defined (, ) /number rows corresponding row /interval objects (ex: c(days(2), days(1))) implementation inspired spark's window API. Implementation Details: Iteration per row window implemented using versatile slider. Application window aggregation can optionally run parallel multiple groups (see argument .) setting future parallel backend. implemented using furrr package. function subsumes regular usecases mutate","code":""},{"path":[]},{"path":"/reference/mutate_.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Drop-in replacement for mutate — mutate_","text":"","code":"library(\"magrittr\") # example 1 # Using iris dataset, # compute cumulative mean of column `Sepal.Length` # ordered by `Petal.Width` and `Sepal.Width` columns # grouped by `Petal.Length` column iris %>% mutate_(sl_mean = mean(Sepal.Length), .order_by = c(\"Petal.Width\", \"Sepal.Width\"), .by = \"Petal.Length\", .frame = c(Inf, 0), ) %>% dplyr::slice_min(n = 3, Petal.Width, by = Species) #> # A tibble: 15 × 6 #> Petal.Length Sepal.Length Sepal.Width Petal.Width Species sl_mean #> #> 1 1.4 4.8 3 0.1 setosa 4.8 #> 2 1.4 4.9 3.6 0.1 setosa 4.85 #> 3 1.1 4.3 3 0.1 setosa 4.3 #> 4 1.5 4.9 3.1 0.1 setosa 4.9 #> 5 1.5 5.2 4.1 0.1 setosa 5.05 #> 6 3.5 5 2 1 versicolor 5 #> 7 3.5 5.7 2.6 1 versicolor 5.35 #> 8 3.3 4.9 2.4 1 versicolor 4.95 #> 9 3.3 5 2.3 1 versicolor 5 #> 10 4.1 5.8 2.7 1 versicolor 5.8 #> 11 4 6 2.2 1 versicolor 6 #> 12 3.7 5.5 2.4 1 versicolor 5.5 #> 13 5.6 6.1 2.6 1.4 virginica 6.1 #> 14 5.1 6.3 2.8 1.5 virginica 6.3 #> 15 5 6 2.2 1.5 virginica 6 # example 2 # Using a sample airquality dataset, # compute mean temp over last seven days in the same month for every row set.seed(101) airquality %>% # create date column dplyr::mutate(date_col = lubridate::make_date(1973, Month, Day)) %>% # create gaps by removing some days dplyr::slice_sample(prop = 0.8) %>% dplyr::arrange(date_col) %>% # compute mean temperature over last seven days in the same month tidier::mutate(avg_temp_over_last_week = mean(Temp, na.rm = TRUE), .order_by = \"Day\", .by = \"Month\", .frame = c(lubridate::days(7), # 7 days before current row lubridate::days(-1) # do not include current row ), .index = \"date_col\" ) #> # A tibble: 122 × 8 #> Month Ozone Solar.R Wind Temp Day date_col avg_temp_over_last_week #> #> 1 5 36 118 8 72 2 1973-05-02 NaN #> 2 5 12 149 12.6 74 3 1973-05-03 72 #> 3 5 18 313 11.5 62 4 1973-05-04 73 #> 4 5 NA NA 14.3 56 5 1973-05-05 69.3 #> 5 5 28 NA 14.9 66 6 1973-05-06 66 #> 6 5 23 299 8.6 65 7 1973-05-07 66 #> 7 5 19 99 13.8 59 8 1973-05-08 65.8 #> 8 5 8 19 20.1 61 9 1973-05-09 64.9 #> 9 5 NA 194 8.6 69 10 1973-05-10 63.3 #> 10 5 16 256 9.7 69 12 1973-05-12 62.7 #> # ℹ 112 more rows"},{"path":"/reference/remove_common_nested_columns.html","id":null,"dir":"Reference","previous_headings":"","what":"Remove non-list columns when same are present in a list column — remove_common_nested_columns","title":"Remove non-list columns when same are present in a list column — remove_common_nested_columns","text":"Remove non-list columns present list column","code":""},{"path":"/reference/remove_common_nested_columns.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Remove non-list columns when same are present in a list column — remove_common_nested_columns","text":"","code":"remove_common_nested_columns(df, list_column)"},{"path":"/reference/remove_common_nested_columns.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Remove non-list columns when same are present in a list column — remove_common_nested_columns","text":"df input dataframe list_column Name expr column list named lists","code":""},{"path":"/reference/remove_common_nested_columns.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Remove non-list columns when same are present in a list column — remove_common_nested_columns","text":"dataframe","code":""},{"path":"/news/index.html","id":"tidier-010-on-github-2023-06-01","dir":"Changelog","previous_headings":"","what":"tidier 0.1.0 (on github: 2023-06-01)","title":"tidier 0.1.0 (on github: 2023-06-01)","text":"Exposed slider’s .complete argument tidier::mutate bugfix: mutate can now modify column (name) sliding operation.","code":""},{"path":"/news/index.html","id":"tidier-001","dir":"Changelog","previous_headings":"","what":"tidier 0.0.1","title":"tidier 0.0.1","text":"CRAN release: 2023-04-27 Added NEWS.md file track changes package.","code":""}] diff --git a/docs/sitemap.xml b/docs/sitemap.xml index fc443c6..c5205ab 100644 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -24,4 +24,7 @@ /reference/mutate_.html + + /reference/remove_common_nested_columns.html + diff --git a/man/mutate.Rd b/man/mutate.Rd index c8c2f97..77e1aee 100644 --- a/man/mutate.Rd +++ b/man/mutate.Rd @@ -4,7 +4,7 @@ \alias{mutate} \title{Drop-in replacement for \code{\link[dplyr]{mutate}}} \usage{ -mutate(x, ..., .by, .order_by, .frame, .index) +mutate(x, ..., .by, .order_by, .frame, .index, .complete = FALSE) } \arguments{ \item{x}{(data.frame)} @@ -23,6 +23,11 @@ and after can be objects. See examples.} \item{.index}{(expression, optional: Yes) index column} + +\item{.complete}{(flag, default: FALSE) This will be passed to +\code{slider::slide} / \code{slider::slide_vec}. Should the function be evaluated on +complete windows only? If FALSE, the default, then partial computations +will be allowed.} } \value{ data.frame @@ -77,34 +82,22 @@ iris \%>\% # Using a sample airquality dataset, # compute mean temp over last seven days in the same month for every row +set.seed(101) airquality \%>\% # create date column - dplyr::mutate(date_col = as.Date(paste("1973", - stringr::str_pad(Month, - width = 2, - side = "left", - pad = "0" - ), - stringr::str_pad(Day, - width = 2, - side = "left", - pad = "0" - ), - sep = "-" - ) - ) - ) \%>\% + dplyr::mutate(date_col = lubridate::make_date(1973, Month, Day)) \%>\% # create gaps by removing some days dplyr::slice_sample(prop = 0.8) \%>\% + dplyr::arrange(date_col) \%>\% # compute mean temperature over last seven days in the same month - mutate(avg_temp_over_last_week = mean(Temp, na.rm = TRUE), - .order_by = Day, - .by = Month, - .frame = c(lubridate::days(7), # 7 days before current row - lubridate::days(-1) # do not include current row - ), - .index = date_col - ) + tidier::mutate(avg_temp_over_last_week = mean(Temp, na.rm = TRUE), + .order_by = Day, + .by = Month, + .frame = c(lubridate::days(7), # 7 days before current row + lubridate::days(-1) # do not include current row + ), + .index = date_col + ) } \seealso{ mutate_ diff --git a/man/mutate_.Rd b/man/mutate_.Rd index c8ffbb6..f2953e4 100644 --- a/man/mutate_.Rd +++ b/man/mutate_.Rd @@ -4,7 +4,16 @@ \alias{mutate_} \title{Drop-in replacement for \code{\link[dplyr]{mutate}}} \usage{ -mutate_(x, ..., .by, .order_by, .frame, .index, .desc = FALSE) +mutate_( + x, + ..., + .by, + .order_by, + .frame, + .index, + .desc = FALSE, + .complete = FALSE +) } \arguments{ \item{x}{(data.frame)} @@ -26,6 +35,11 @@ objects. See examples.} \item{.desc}{(logical_vector, default: FALSE) bool or logical vector of same length as \code{.order_by}.} + +\item{.complete}{(flag, default: FALSE) This will be passed to +\code{slider::slide} / \code{slider::slide_vec}. Should the function be evaluated on +complete windows only? If FALSE, the default, then partial computations +will be allowed.} } \value{ data.frame @@ -81,34 +95,22 @@ iris \%>\% # Using a sample airquality dataset, # compute mean temp over last seven days in the same month for every row +set.seed(101) airquality \%>\% # create date column - dplyr::mutate(date_col = as.Date(paste("1973", - stringr::str_pad(Month, - width = 2, - side = "left", - pad = "0" - ), - stringr::str_pad(Day, - width = 2, - side = "left", - pad = "0" - ), - sep = "-" - ) - ) - ) \%>\% + dplyr::mutate(date_col = lubridate::make_date(1973, Month, Day)) \%>\% # create gaps by removing some days dplyr::slice_sample(prop = 0.8) \%>\% + dplyr::arrange(date_col) \%>\% # compute mean temperature over last seven days in the same month - mutate_(avg_temp_over_last_week = mean(Temp, na.rm = TRUE), - .order_by = "Day", - .by = "Month", - .frame = c(lubridate::days(7), # 7 days before current row - lubridate::days(-1) # do not include current row - ), - .index = "date_col" - ) + tidier::mutate(avg_temp_over_last_week = mean(Temp, na.rm = TRUE), + .order_by = "Day", + .by = "Month", + .frame = c(lubridate::days(7), # 7 days before current row + lubridate::days(-1) # do not include current row + ), + .index = "date_col" + ) } \seealso{ mutate diff --git a/man/remove_common_nested_columns.Rd b/man/remove_common_nested_columns.Rd new file mode 100644 index 0000000..7a49d94 --- /dev/null +++ b/man/remove_common_nested_columns.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/mutate.R +\name{remove_common_nested_columns} +\alias{remove_common_nested_columns} +\title{Remove non-list columns when same are present in a list column} +\usage{ +remove_common_nested_columns(df, list_column) +} +\arguments{ +\item{df}{input dataframe} + +\item{list_column}{Name or expr of the column which is a list of named lists} +} +\value{ +dataframe +} +\description{ +Remove non-list columns when same are present in a list column +} diff --git a/tests/testthat/tests_tidier.R b/tests/testthat/tests_tidier.R index fc6a16c..e7aa4d0 100644 --- a/tests/testthat/tests_tidier.R +++ b/tests/testthat/tests_tidier.R @@ -3,12 +3,12 @@ test_that("basic mutate", { res = iris %>% mutate(sl_pl_1 = Sepal.Length + 1) - testthat::expect(inherits(res, "data.frame")) + testthat::expect(inherits(res, "data.frame"), "not a df") res = iris %>% mutate_(sl_pl_1 = Sepal.Length + 1) - testthat::expect(inherits(res, "data.frame")) + testthat::expect(inherits(res, "data.frame"), "not a df") }) test_that("order_by without by", { @@ -19,7 +19,7 @@ test_that("order_by without by", { ) %>% dplyr::arrange(Petal.Width) - testthat::expect(inherits(res, "data.frame")) + testthat::expect(inherits(res, "data.frame"), "not a df") # involved order_by res = iris %>% @@ -28,7 +28,7 @@ test_that("order_by without by", { ) %>% dplyr::arrange(desc(Petal.Width), Sepal.Length) - testthat::expect(inherits(res, "data.frame")) + testthat::expect(inherits(res, "data.frame"), "not a df") res = iris %>% mutate_(sl_pl_1 = cumsum(Sepal.Length), @@ -36,7 +36,7 @@ test_that("order_by without by", { ) %>% dplyr::arrange(Petal.Width) - testthat::expect(inherits(res, "data.frame")) + testthat::expect(inherits(res, "data.frame"), "not a df") res = iris %>% mutate_(sl_pl_1 = cumsum(Sepal.Length), @@ -45,7 +45,7 @@ test_that("order_by without by", { ) %>% dplyr::arrange(desc(Petal.Width), Sepal.Length) - testthat::expect(inherits(res, "data.frame")) + testthat::expect(inherits(res, "data.frame"), "not a df") }) test_that("order_by with by", { @@ -59,7 +59,7 @@ test_that("order_by with by", { dplyr::select(-rn) %>% dplyr::slice_min(n = 3, Petal.Width, by = Species) - testthat::expect(inherits(res, "data.frame")) + testthat::expect(inherits(res, "data.frame"), "not a df") res = iris %>% dplyr::mutate(rn = dplyr::row_number()) %>% @@ -70,7 +70,7 @@ test_that("order_by with by", { dplyr::select(-rn) %>% dplyr::slice_min(n = 3, Petal.Width, by = Species) - testthat::expect(inherits(res, "data.frame")) + testthat::expect(inherits(res, "data.frame"), "not a df") }) test_that("order_by, with by, with frame", { @@ -83,7 +83,7 @@ test_that("order_by, with by, with frame", { ) %>% dplyr::slice_min(n = 3, Petal.Width, by = Species) - testthat::expect(inherits(res, "data.frame")) + testthat::expect(inherits(res, "data.frame"), "not a df") res = iris %>% mutate_(sl_mean = mean(Sepal.Length), @@ -93,7 +93,7 @@ test_that("order_by, with by, with frame", { ) %>% dplyr::slice_min(n = 3, Petal.Width, by = Species) - testthat::expect(inherits(res, "data.frame")) + testthat::expect(inherits(res, "data.frame"), "not a df") }) test_that("order_by, with by, with frame, with index", { @@ -126,7 +126,7 @@ test_that("order_by, with by, with frame, with index", { ), .index = date_col ) - testthat::expect(inherits(res, "data.frame")) + testthat::expect(inherits(res, "data.frame"), "not a df") res = airquality %>% # create date column @@ -156,5 +156,114 @@ test_that("order_by, with by, with frame, with index", { ), .index = "date_col" ) - testthat::expect(inherits(res, "data.frame")) + testthat::expect(inherits(res, "data.frame"), "not a df") +}) + +test_that("order_by, with by, with frame, same column name", { + + res = iris %>% + mutate(Sepal.Length = mean(Sepal.Length), + .frame = c(Inf, 0), + .order_by = Petal.Width, + .by = c(Petal.Length, Sepal.Width) + ) %>% + dplyr::slice_min(n = 3, Petal.Width, by = Species) + + testthat::expect(inherits(res, "data.frame"), "not a df") + + res = iris %>% + mutate_(Sepal.Length = mean(Sepal.Length), + .frame = c(Inf, 0), + .order_by = "Petal.Width", + .by = c("Species", "Petal.Length") + ) %>% + dplyr::slice_min(n = 3, Petal.Width, by = Species) + + testthat::expect(inherits(res, "data.frame"), "not a df") +}) + +test_that("order_by, with by, with frame, same column name", { + + res = iris %>% + mutate(Sepal.Length = mean(Sepal.Length), + .frame = c(Inf, 0), + .order_by = Petal.Width, + .by = c(Petal.Length, Sepal.Width) + ) %>% + dplyr::slice_min(n = 3, Petal.Width, by = Species) + + testthat::expect(inherits(res, "data.frame"), "not a df") + + res = iris %>% + mutate_(Sepal.Length = mean(Sepal.Length), + .frame = c(Inf, 0), + .order_by = "Petal.Width", + .by = c("Species", "Petal.Length") + ) %>% + dplyr::slice_min(n = 3, Petal.Width, by = Species) + + testthat::expect(inherits(res, "data.frame"), "not a df") +}) + +test_that("order_by, with by, with frame, with index, with same column", { + + res = airquality %>% + # create date column + dplyr::mutate(date_col = as.Date(paste("1973", + stringr::str_pad(Month, + width = 2, + side = "left", + pad = "0" + ), + stringr::str_pad(Day, + width = 2, + side = "left", + pad = "0" + ), + sep = "-" + ) + ) + ) %>% + # create gaps by removing some days + dplyr::slice_sample(prop = 0.8) %>% + # compute mean temperature over last seven days in the same month + mutate(Temp = mean(Temp, na.rm = TRUE), + .order_by = Day, + .by = Month, + .frame = c(lubridate::days(7), # 7 days before current row + lubridate::days(-1) # do not include current row + ), + .index = date_col + ) + testthat::expect(inherits(res, "data.frame"), "not a df") + + res = airquality %>% + # create date column + dplyr::mutate(date_col = as.Date(paste("1973", + stringr::str_pad(Month, + width = 2, + side = "left", + pad = "0" + ), + stringr::str_pad(Day, + width = 2, + side = "left", + pad = "0" + ), + sep = "-" + ) + ) + ) %>% + # create gaps by removing some days + dplyr::slice_sample(prop = 0.8) %>% + # compute mean temperature over last seven days in the same month + mutate_(Temp = mean(Temp, na.rm = TRUE), + .order_by = "Day", + .by = "Month", + .frame = c(lubridate::days(7), # 7 days before current row + lubridate::days(-1) # do not include current row + ), + .index = "date_col" + ) + testthat::expect(inherits(res, "data.frame"), "not a df") })