Skip to content

Commit

Permalink
bug fixes pass CRAN check
Browse files Browse the repository at this point in the history
  • Loading branch information
christophergandrud committed Nov 18, 2014
1 parent e41aba8 commit 9a73d79
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Title: R tools for making it easier to combine and clean data sets.
Description: R tools for combining and cleaning data sets, including filling in
missing observations with data from another data frame and creating
lag/lead variables.
Version: 0.2.6
Version: 0.2.7
Date: 2014-11-08
Author: Christopher Gandrud
Maintainer: Christopher Gandrud <[email protected]>
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export(slide)
export(slideMA)
import(data.table)
importFrom(dplyr,group_by)
importFrom(dplyr,group_by_)
importFrom(dplyr,mutate)
importFrom(dplyr,summarize)
importFrom(dplyr,ungroup)
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Version 0.2.7

Fixed a bug in `slide` when there are invalid sliding values.

### Version 0.2.6

- Fixed a misspelling in the `CountSpell` documentation. Thanks to
Expand Down
19 changes: 13 additions & 6 deletions R/slide.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
#' \url{http://ctszkin.com/2012/03/11/generating-a-laglead-variables/}
#'
#'
#' @importFrom dplyr group_by summarize mutate ungroup
#' @importFrom dplyr group_by group_by_ summarize mutate ungroup
#' @export

slide <- function(data, Var, GroupVar = NULL, NewVar = NULL, slideBy = -1,
Expand Down Expand Up @@ -111,22 +111,29 @@ slide <- function(data, Var, GroupVar = NULL, NewVar = NULL, slideBy = -1,

# Drop if there are not enough observations per group to slide
if (!is.null(GroupVar)){
data <- group_by_(data, .dots = GroupVar)
data <- group_by_(data, .dots = GroupVar)
data$fake <- 1
Minimum <- abs(slideBy) - 1
Summed <- dplyr::mutate(data, total = sum(fake))
SubSummed <- subset(Summed, total <= Minimum)
data <- VarDrop(data, 'fake')
FullData <- NULL
if (nrow(SubSummed) > 0){
if (nrow(SubSummed) == 0) {
FullData <- NULL
}
else if (nrow(SubSummed) > 0){
## Hack
FullData <- data
class(FullData) <- 'data.frame'
## End Hack

Dropping <- unique(SubSummed[, GroupVar])

## Hack
class(data) <- 'data.frame'
data <- data[!(data[, GroupVar] %in% Dropping), ]
data <- group_by_(data, .dots = GroupVar)
## End Hack

if (!isTRUE(keepInvalid)){
message(paste0('\nWarning: the following groups have ', Minimum,
' or fewer observations.',
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ DataCombine

Christopher Gandrud

Version 0.2.6
Version 0.2.7
[![Build Status](https://travis-ci.org/christophergandrud/DataCombine.png)](https://travis-ci.org/christophergandrud/DataCombine)

Please report any **bugs** or **suggestions** at:
Expand Down

0 comments on commit 9a73d79

Please sign in to comment.