Skip to content

Commit

Permalink
version 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
wahani authored and cran-robot committed Apr 21, 2017
1 parent cd0263d commit 35de62b
Show file tree
Hide file tree
Showing 29 changed files with 186 additions and 111 deletions.
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: dat
Type: Package
Title: Tools for Data Manipulation
Version: 0.1.0
Version: 0.2.0
Authors@R: person("Sebastian", "Warnholz", role = c("aut", "cre"),
email = "wahani@gmail.com")
BugReports: https://github.com/wahani/dat/issues
Expand All @@ -17,13 +17,13 @@ Suggests: lintr, knitr, microbenchmark, nycflights13, rmarkdown,
VignetteBuilder: knitr
Encoding: UTF-8
ByteCompile: TRUE
RoxygenNote: 5.0.1
RoxygenNote: 6.0.1
Collate: 'NAMESPACE.R' 'FormulaList.R' 'helper.R' 'DataFrame.R'
'as.function.R' 'bindRows.R' 'extract.R' 'map.R' 'mutar.R'
'pipeExport.R' 'replace.R' 'verboseApply.R'
NeedsCompilation: no
Packaged: 2017-01-06 11:46:41 UTC; sebastian
Packaged: 2017-04-20 18:26:40 UTC; sebastian
Author: Sebastian Warnholz [aut, cre]
Maintainer: Sebastian Warnholz <wahani@gmail.com>
Repository: CRAN
Date/Publication: 2017-01-07 02:04:18
Date/Publication: 2017-04-21 05:54:04 UTC
55 changes: 28 additions & 27 deletions MD5
Original file line number Diff line number Diff line change
@@ -1,44 +1,45 @@
e22e619da7849f57743c1b55f9ea1e99 *DESCRIPTION
7d0270661448d8fa8c46e361b89908e1 *DESCRIPTION
3ef5f860686c2300ffa18a3b4068b847 *LICENSE
e69132838f9a355284c1f9fb25a5ce60 *NAMESPACE
e72b5ef52e6cfc3d7e8c759644fc0216 *NEWS
a3a8720b4cc6b1af95110e6ac0831faa *R/DataFrame.R
9e228fb69437ebc3b344e9d09e12754d *NEWS
a8a4aef97162fa86d555783ef97ec059 *R/DataFrame.R
203a4d90cb2d89459ff556d1646ff93e *R/FormulaList.R
f068aac61b7e63721803f1fd953a5006 *R/NAMESPACE.R
b8040f5cc62cd1bbe5bf7573712dd009 *R/NAMESPACE.R
6ed84d57729b7e2cef1ec270b33a17b0 *R/as.function.R
e2570aefa456d9f9dad3b2d804cd1755 *R/bindRows.R
b45747e965312a811b300684a4dfce02 *R/extract.R
bed419bcfc5e2c6c18fbdec4f78afe10 *R/helper.R
6ae1bdd5c01ead629171bd7f7af8d78f *R/bindRows.R
73ca6235ad820f2b6e2bd51cf406bf33 *R/extract.R
86af534edc17d58555eb2376cfb16fe5 *R/helper.R
34aad9ebac9fa62ff570be0b1802176c *R/map.R
daa778e13d6bbcb774ff3e89e85d4ca1 *R/mutar.R
ed550bac5869b063ca78167be0480919 *R/pipeExport.R
46d295251dfe4025d0220406377b6127 *R/replace.R
600e2cc63e4ce571d43295fbb121309d *R/replace.R
8349f5f0ff4fe739cb5f98bba2a8fc8a *R/verboseApply.R
f98cccd54d8e5a383f641fa536107fc0 *build/vignette.rds
4ae7433651e95e61c094f455ad8eb48b *inst/doc/Introduction.R
d4cd008acf1a43564109b5119a9fdd2b *inst/doc/Introduction.Rmd
6c848ec420bafa5a4d4b4aa3bb07f1a4 *inst/doc/Introduction.html
6104aa16747f5d659287fd43593cf2a9 *build/vignette.rds
9c4d1fef2ec3edacbc80a6cba936ef02 *inst/doc/Introduction.R
76afb7f9c86d56a4f4f61ade219cc3c4 *inst/doc/Introduction.Rmd
94447b9a6ef8d5117c307f3c84bc32de *inst/doc/Introduction.html
5ee809f2b4635858ed08480c568466c1 *inst/doc/performance.R
2087fde06d8692d0b181a704bdd374ed *inst/doc/performance.Rmd
f6285b2989062546e293d1a858aac219 *inst/doc/performance.html
f8cdd099282632cc21d5c7a96964f9c9 *man/DataFrame.Rd
9300a75bb08fee02da4d333b6a4e77ed *man/FormulaList.Rd
a5258f9f9eb9320edc4d600a2b82c395 *man/as.function.formula.Rd
bcb865019070b0f1424ff78650a2ef6f *man/bindRows.Rd
95b86c71fa088d81ed805a8d7b4eab0a *man/extract.Rd
cbd7b4d1bb1ea2262b07b5f8a40339bd *man/map.Rd
aa23306b35dfd212c668cc65d2283770 *man/mutar.Rd
e1c15799c328c92e30301d8330e76dfd *man/reexports.Rd
504383202ab2e2493b9b314005c58384 *man/replace.Rd
af1480b49f8b300002de24b870dfb01b *man/verboseApply.Rd
7b8d3af409ab6dd8555761a8f2d8d8c7 *inst/doc/performance.html
68cfb8a343293c0ecd5b673ac18007bf *man/DataFrame.Rd
f1fd9bbae5187167e6aaf1b0241b67b4 *man/FormulaList.Rd
816256192a447a7c1e23704ae34cd9e0 *man/as.function.formula.Rd
6c7c515ef76e8875a9b88aee69a87afc *man/bindRows.Rd
4ec7c36799f9b0eb3db017a6176b8359 *man/extract.Rd
f01ccb3e48f0b6d75f9b8c655f28df32 *man/map.Rd
2f8f611e761410086b8825318df20814 *man/mutar.Rd
43fc8cf4f475cedf523ad417c6036de7 *man/reexports.Rd
f321d684257ae3fa6e73824eef320ff1 *man/replace.Rd
81ff3a8bf589540cd2105e7ff2864b84 *man/verboseApply.Rd
93fd7f973ca45045b74ed46d2a326bb9 *tests/testthat.R
51e4c76289a997d53102a94163e880c7 *tests/testthat/test-DataFrame.R
ccbcadf672b3f067556b13d1b958447f *tests/testthat/test-DataFrame.R
4ba80b76799a30783ccdcd5f43e05bbb *tests/testthat/test-S4attach.R
ef934678bf32bcca1516cd4d42ee0ec4 *tests/testthat/test-as.function.R
7509ba7b2875e2fa297611b0054b5a99 *tests/testthat/test-extract.R
d4947283fcd0535990c3534d8a33ccd4 *tests/testthat/test-lintr.R
518d9a5e0edfa3d2005b0915c46f26f0 *tests/testthat/test-makeFormulas.R
dc96ce3c8c9a650bd2fc6a03efc69e5c *tests/testthat/test-map.R
5f05065c2c0b3741d8bd126b14ec9a55 *tests/testthat/test-mutar.R
9752d78e50caf46a1d131734f5416a76 *tests/testthat/test-map.R
508812893e118e6789ec96b1a5b3dd66 *tests/testthat/test-mutar.R
ddfb8a400497143807f6787ae17a6be9 *tests/testthat/test-replace.R
d4cd008acf1a43564109b5119a9fdd2b *vignettes/Introduction.Rmd
76afb7f9c86d56a4f4f61ade219cc3c4 *vignettes/Introduction.Rmd
2087fde06d8692d0b181a704bdd374ed *vignettes/performance.Rmd
13 changes: 13 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
* Version 0.2.0
- CRAN release

* Version 0.1.3
- Fix for change in dplyr: mutate changes class of input (mutar does not)
- Fix for change in dplyr: bind_rows cannot handle S4 dfs. switched to rbindlist

* Version 0.1.2
- Fix for S4 when package not attached.

* Version 0.1.1
- Default methods for replace, extract, extract2

* Version 0.1.0
- CRAN release

Expand Down
6 changes: 2 additions & 4 deletions R/DataFrame.R
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ handleCols(x ~ data.frame,
..., by ~ NULL, sby ~ character) %m% {
args <- constructArgs(i, j, ..., dat = x)
dplyr::group_by_(x, .dots = sby) %>%
dplyr::summarise_(.dots = args) %>%
as.data.frame
dplyr::summarise_(.dots = args)
}

handleCols(x ~ data.frame,
Expand All @@ -180,6 +179,5 @@ handleCols(x ~ data.frame,
..., by ~ character, sby ~ NULL) %m% {
args <- constructArgs(i, j, ..., dat = x)
dplyr::group_by_(x, .dots = by) %>%
dplyr::mutate_(.dots = args) %>%
as.data.frame
dplyr::mutate_(.dots = args)
}
13 changes: 11 additions & 2 deletions R/NAMESPACE.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Notes:
#
# - Need to import data.table so dplyr functions can handle that format. If not
# I get obscure error messages from dplyr functions.

Expand All @@ -14,6 +15,14 @@ NULL

setClassUnion(
"atomic",
c("logical", "integer", "numeric", "complex", "character", "raw"),
topenv(environment())
c("logical", "integer", "numeric", "complex", "character", "raw")
)

# This package uses S4. If we use the package without attaching it (using `::`
# instead of `library`) some things may not work. This can only be changed by
# not using S4; which involves too much time and effort to get rid of at this
# point. Hence we have to make sure, that as soon something from this package is
# used, 'methods' is attached - simply importing it is not enough:
setLoadAction(function(ns) {
eval(parse(text = "library('methods')"), envir = ns)
})
16 changes: 9 additions & 7 deletions R/bindRows.R
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
#' Bind rows
#'
#' This is a wrapper around \link[dplyr]{bind_rows} to preserve the input class.
#'
#' @param x (list)
#' @param id passed to \link[dplyr]{bind_rows} as \code{.id}
#' This is a wrapper around \link[data.table]{rbindlist} to preserve the input
#' class.
#'
#' @param x (list) a list of data frames
#' @param id,useNames,fill passed to \link[data.table]{rbindlist}
#'
#' @return
#' If the first element of \code{x} inherits from \code{data.frame} the type
#' that first eleent.
#' that first element.
#'
#' \code{x} else.
#'
#' @export
bindRows <- function(x, id = NULL) {
bindRows <- function(x, id = NULL, useNames = TRUE, fill = TRUE) {
if (inherits(x[[1]], "data.frame")) {
memClassHandler <- MemClassHandler()
memClassHandler$memClass(x[[1]])
dplyr::bind_rows(x, .id = id) %>% memClassHandler$wrapClass()
ret <- data.table::rbindlist(x, idcol = id, use.names = useNames, fill = fill)
memClassHandler$wrapClass(ret)
} else {
x
}
Expand Down
5 changes: 2 additions & 3 deletions R/extract.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
#' }
#'
#' extract(1:10, isPrime)
extract(x, ind, ...) %g% standardGeneric("extract")
extract(x, ind, ...) %g% x[ind, ...]

#' @export
#' @rdname extract
Expand Down Expand Up @@ -100,12 +100,11 @@ extract(x ~ data.frame, ind ~ character, ...) %m% {

#' @export
#' @rdname extract
extract2(x, ind, ...) %g% standardGeneric("extract2")
extract2(x, ind, ...) %g% x[[ind]]

#' @export
#' @rdname extract
extract2(x ~ atomic | list, ind ~ numeric | integer, ...) %m% {
stopifnot(length(ind) == 1)
x[[ind]]
}

Expand Down
18 changes: 15 additions & 3 deletions R/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ML <- function(...) new("MList", list(...))
MList <- function(...) new("MList", list(...))


MemClassHandler <- function() {
MemClassHandler <- function(x) {
# An instance can be used to memorize the class of an object. And then to add
# that class, or wrap that S4 instance to an object.

Expand All @@ -31,13 +31,16 @@ MemClassHandler <- function() {
}

wrapClass <- function(x) {
# dplyr and data.table are sometimes eager to add their own classes. To
# avoid conflicts, especially with S4, they are removed first:
x <- if (inherits(x, "data.frame")) as.data.frame(x) else x
if (!is.null(s4Object)) {
out <- s4Object
S3Part(out) <- addClass(x, classOfX)
S3Part(out) <- class(x, classOfX)
out
}
else if (!is.null(classOfX)) {
addClass(x, classOfX)
class(x, classOfX)
}
else {
stop("Don't know what this is.")
Expand Down Expand Up @@ -112,6 +115,15 @@ addClass <- function(x, class) {
x
}

class <- function(x, class) {
if (missing(class)) {
base::class(x)
} else {
class(x) <- class
x
}
}

constructArgs <- function(i, j, ..., dat) {
# constructs arguments (name-value expressions) for the use in mutate and
# summarise.
Expand Down
2 changes: 1 addition & 1 deletion R/replace.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#' replace(list(x = 1, y = 2), "x", 0)
#' replace(list(x = 1, y = 2), "^x$", 0)
#' replace(list(x = 1, y = "a"), is.character, NULL)
replace(x, ind, values, ...) %g% standardGeneric("replace")
replace(x, ind, values, ...) %g% base::replace(x, ind, values)

#' @export
#' @rdname replace
Expand Down
Binary file modified build/vignette.rds
Binary file not shown.
3 changes: 3 additions & 0 deletions inst/doc/Introduction.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ cat(gsub("\\n ", "", packageDescription("dat", fields = "Description")))
## ----eval=FALSE----------------------------------------------------------
# devtools::install_github("wahani/dat")

## ----eval=FALSE----------------------------------------------------------
# install.packages("dat")

## ------------------------------------------------------------------------
library("nycflights13")
library("dat")
Expand Down
9 changes: 9 additions & 0 deletions inst/doc/Introduction.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,19 @@ cat(gsub("\\n ", "", packageDescription("dat", fields = "Description")))

## Installation

### From GitHub

```{r eval=FALSE}
devtools::install_github("wahani/dat")
```

### From CRAN

```{r eval=FALSE}
install.packages("dat")
```


## Why should you care?

- You probably have to rewrite all your dplyr / data.table code once you put it
Expand Down
19 changes: 10 additions & 9 deletions inst/doc/Introduction.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

<head>

<meta charset="utf-8">
<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />

<meta name="viewport" content="width=device-width, initial-scale=1">


<meta name="date" content="2017-01-06" />
<meta name="date" content="2017-04-19" />

<title>Tools for Data Manipulation</title>

Expand Down Expand Up @@ -68,15 +68,22 @@


<h1 class="title toc-ignore">Tools for Data Manipulation</h1>
<h4 class="date"><em>2017-01-06</em></h4>
<h4 class="date"><em>2017-04-19</em></h4>



<p>An implementation of common higher order functions with syntactic sugar for anonymous function. Provides also a link to ‘dplyr’ for common transformations on data frames to work around non standard evaluation by default.</p>
<div id="installation" class="section level2">
<h2>Installation</h2>
<div id="from-github" class="section level3">
<h3>From GitHub</h3>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">devtools::<span class="kw">install_github</span>(<span class="st">&quot;wahani/dat&quot;</span>)</code></pre></div>
</div>
<div id="from-cran" class="section level3">
<h3>From CRAN</h3>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">install.packages</span>(<span class="st">&quot;dat&quot;</span>)</code></pre></div>
</div>
</div>
<div id="why-should-you-care" class="section level2">
<h2>Why should you care?</h2>
<ul>
Expand All @@ -91,12 +98,6 @@ <h2>A link to <code>dplyr</code></h2>
<p>The examples are from the introductory vignette of <code>dplyr</code>. You still work with data frames: so you can simply mix in dplyr features whenever you need them. The functions <code>filtar</code>, <code>mutar</code> and <code>sumar</code> are <code>R CMD check</code> friendly replacements for the corresponding versions in <code>dplyr</code>. For <code>select</code> you can use <code>extract</code>. The function names are chosen so that they are similar but do not conflict with <code>dplyr</code>s function names - so <code>dplyr</code> can be savely attached to the search path.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">library</span>(<span class="st">&quot;nycflights13&quot;</span>)
<span class="kw">library</span>(<span class="st">&quot;dat&quot;</span>)</code></pre></div>
<pre><code>## Loading required package: aoos</code></pre>
<pre><code>##
## Attaching package: 'dat'</code></pre>
<pre><code>## The following object is masked from 'package:base':
##
## replace</code></pre>
<div id="select-rows" class="section level3">
<h3>Select rows</h3>
<p><code>filtar</code> can be used as a replacement for <code>filter</code> and <code>slice</code>. When you reference a variable in the data itself, you can indicate this by using a one sided formula.</p>
Expand Down
2 changes: 1 addition & 1 deletion inst/doc/performance.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<head>

<meta charset="utf-8">
<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />

Expand Down
6 changes: 3 additions & 3 deletions man/DataFrame.Rd

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

1 change: 0 additions & 1 deletion man/FormulaList.Rd

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

1 change: 0 additions & 1 deletion man/as.function.formula.Rd

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

Loading

0 comments on commit 35de62b

Please sign in to comment.