Skip to content

Commit

Permalink
Sketches
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau-lilly committed Jan 15, 2019
1 parent fc1fda1 commit 50c0f06
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions R/api-transform.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ tf_row <- function(plan, row) {
paste0("tf_", as.character(call[[1]])),
envir = getNamespace("drake")
)
transform(plan, plan$target[[row]], plan$command[[row]], tf_levels(call))
transform(
plan,
plan$target[[row]],
plan$command[[row]],
tf_levels(plan, call)
)
}

# Supported transformations
Expand All @@ -65,15 +70,20 @@ tf_cross <- function(plan, target, command, levels) {

# Utils

tf_levels <- function(call) {
tf_levels <- function(plan, call) {
out <- lapply(call[-1], as.character)
names <- names(out)
if (!length(names)) {
names <- rep("", length(out))
factors <- names(out)
if (!length(factors)) {
factors <- rep("", length(out))
}
factors[!nzchar(factors)] <- unlist(lapply(out[!nzchar(factors)], `[[`, 1))
names(out) <- factors
out <- lapply(out, `[`, -1)
for (factor in factors) {
if (!length(out[[factor]])) {
out$factor <- unique(na.omit(plan[[factor]]))
}
}
names[!nzchar(names)] <- unlist(lapply(out[!nzchar(names)], `[[`, 1))
names(out) <- names
lapply(out, `[`, -1)
}

tf_cols <- function(plan) {
Expand Down

1 comment on commit 50c0f06

@lintr-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

R/api-transform.R:30:8: style: Place a space before left parenthesis, except in a function call.

while(row < nrow(plan)) {
       ^

R/api-transform.R:33:11: style: Trailing whitespace is superfluous.

next 
          ^

Please sign in to comment.