Skip to content

Commit

Permalink
add rlang
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieugomez committed Jul 6, 2017
1 parent 3d0baa7 commit 0aae35f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 15 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Expand Up @@ -17,6 +17,7 @@ Imports:
lazyeval,
matrixStats,
methods,
rlang,
stringr,
tidyr
Suggests:
Expand Down
2 changes: 1 addition & 1 deletion R/fill_gap.R
Expand Up @@ -30,7 +30,7 @@ fill_gap <- function(x, ..., full = FALSE, roll = FALSE, rollends = if (roll=="
originalattributes <- attributes(x)$class

# check byvars, timevar form a panel
stopifnot(is.panel(x, !!as.name(timevar)))
stopifnot(is.panel(x, !!rlang::sym(timevar)))

# create id x time
ans <- dplyr::select_at(x, c(byvars, timevar))
Expand Down
2 changes: 1 addition & 1 deletion R/is.panel.R
Expand Up @@ -30,7 +30,7 @@ is.panel <- function(x, ..., .dots){
message(paste0("Variable ", timevar, " has missing values in ", length(ans)," row(s): ", paste(as.character(ans),collapse = ",")))
out <- FALSE
}
overall = x %>% group_by(..., add = TRUE) %>% group_indices()
overall = x %>% group_by(..., add = TRUE) %>% dplyr::group_indices()
if (anyDuplicated(overall)){
groups <- split(seq_along(overall), overall)
groups <- groups[vapply(groups, length, integer(1)) > 1]
Expand Down
17 changes: 6 additions & 11 deletions R/join.R
Expand Up @@ -65,8 +65,8 @@ join = function(x, y, kind ,on = intersect(names(x),names(y)), suffixes = c(".x
if (length(intersect(paste0(common_names, suffixes[2]), setdiff(names(y),common_names)))>0) stop(paste("Adding the suffix",suffixes[2],"in", common_names,"would create duplicates names in y"), call. = FALSE)
if (length(common_names)>0){
for (name in common_names){
x <- rename(x, !!paste0(name, suffixes[1]) := !!as.name(name))
y <- rename(y, !!paste0(name, suffixes[2]) := !!as.name(name))
x <- rename(x, !!paste0(name, suffixes[1]) := !!rlang::sym(name))
y <- rename(y, !!paste0(name, suffixes[2]) := !!rlang::sym(name))
}
}
}
Expand Down Expand Up @@ -95,8 +95,6 @@ join = function(x, y, kind ,on = intersect(names(x),names(y)), suffixes = c(".x
x <- dplyr::mutate(x, !!idm := 1L)
idu <- tempname(c(names(x), names(y), gen, idm))
y <- dplyr::mutate(y, !!idu := 1L)
idm_symbol = quo(!!as.name(idm))
idu_symbol = quo(!!as.name(idu))
}
all.x <- FALSE
all.y <- FALSE
Expand All @@ -111,22 +109,19 @@ join = function(x, y, kind ,on = intersect(names(x),names(y)), suffixes = c(".x
}

if (gen != FALSE){
gen_symbol = quo(!!as.name(gen))
out <- dplyr::mutate(out, !!gen := 3L)
out <- dplyr::mutate(out, !!gen := ifelse(is.na(!!idu_symbol), 1, !!gen_symbol))
out <- dplyr::mutate(out, !!gen := ifelse(is.na(!!idm_symbol), 1, !!gen_symbol))
out <- dplyr::mutate(out, !!gen := ifelse(is.na(!!rlang::sym(idu)), 1, !!rlang::sym(gen)))
out <- dplyr::mutate(out, !!gen := ifelse(is.na(!!rlang::sym(idm)), 1, !!rlang::sym(gen)))
out <- dplyr::select_at(out, setdiff(names(out), c(idm, idu)))
}

if (update){
for (v in common_names){
newvx <- paste0(v, suffixes[1])
newvy <- paste0(v, suffixes[2])
newvx_symbol = quo(!!as.name(newvx))
newvy_symbol = quo(!!as.name(newvy))
out <- dplyr::mutate(out, !!newvx := ifelse(is.na(!!newvx_symbol) & !is.na(!!newvy_symbol), !!newvy_symbol, !!newvx_symbol))
out <- dplyr::mutate(out, !!newvx := ifelse(is.na(!!rlang::sym(newvx)) & !is.na(!!rlang::sym(newvy)), !!rlang::sym(newvy), !!rlang::sym(newvx)))
out <- select_at(out, setdiff(names(out), newvy))
out <- rename(out, !!v := !!newvx_symbol)
out <- rename(out, !!v := !!rlang::sym(newvx))
}
}
return(out)
Expand Down
4 changes: 2 additions & 2 deletions R/sum_up.R
Expand Up @@ -2,7 +2,7 @@
#'
#' @param x a data.frame
#' @param ... Variables to include. Defaults to all non-grouping variables. See the \link[dplyr]{select} documentation.
#' @param w Weights. Default to NULL.
#' @param wt Weights. Default to NULL.
#' @param d Should detailed summary statistics be printed?
#' @param .dots Used to work around non-standard evaluation.
#' @examples
Expand Down Expand Up @@ -105,7 +105,7 @@ describe <- function(df, d = FALSE, wtvar = character(0), byvars = character(0)
sum_higher[1] <- sqrt(sum_higher[1])
sum_higher[2] <- sum_higher[2]/sum_higher[1]^3
sum_higher[3] <- sum_higher[3]/sum_higher[1]^4
sum_quantile <- pctile(x_omit, c(0, 0.01, 0.05, 0.1, 0.25, 0.50, 0.75, 0.9, 0.95, 0.99, 1), w = w_omit)
sum_quantile <- pctile(x_omit, c(0, 0.01, 0.05, 0.1, 0.25, 0.50, 0.75, 0.9, 0.95, 0.99, 1), wt = w_omit)
} else{
x_omit <- na.omit(x)
m <- mean(x_omit)
Expand Down

0 comments on commit 0aae35f

Please sign in to comment.