Skip to content

Commit

Permalink
move arg eval to df/call
Browse files Browse the repository at this point in the history
  • Loading branch information
mschubert committed Sep 1, 2017
1 parent 16b4586 commit 9dae849
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
7 changes: 7 additions & 0 deletions data_frame/call.r
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.b = import('../base')
.dp = import_package_('dplyr')
.func = import('../base/functional')

#' Call a function passing each row as arguments
#'
Expand All @@ -23,6 +24,12 @@ call = function(index, fun, const=list(), result_only=FALSE, rep=FALSE, hpc_args
}
}

# evaluate all references, clean function env
call_args = as.list(.func$match_call_defaults())[-1]
for (i in seq_along(call_args))
assign(names(call_args)[i], eval(call_args[[i]], envir=parent.frame()))
rm(list=ls(environment(fun), keep), envir=environment(fun))

# perform function calls either sequentially or with hpc module
#TODO: replace local call by dplyr::do(rowwise(df))
if (is.null(hpc_args))
Expand Down
16 changes: 3 additions & 13 deletions data_frame/wrap_formula_indexing.r
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ wrap_formula_indexing = function(FUN) {
new_FUN = function() {
#' @param ... Arguments as defined in the data.frame row
one_item = function(data, subsets=NULL, ...) {
idx = import_('../base/indexing')
args = list(...)

# subset all iterated data that is not masked by 'atomic' flags
Expand All @@ -27,25 +28,14 @@ wrap_formula_indexing = function(FUN) {
}

func = import_('../base/functional')
idx = import_('../base/indexing')
df = import_('../data_frame')
ci = import('../data_frame/create_formula_index')

#FIXME: commented line below does not work
fca = function(ca) {
if (class(ca) %in% c("name", "call"))
eval(ca, envir=ca_env)
else
ca
}
ca_env = parent.frame()
# replace with: call_args = as.list(func$eval_call())[-1] ?
call_args = as.list(func$match_call_defaults())[-1]
call_args = lapply(call_args, fca)

# call_args = as.list(func$eval_call())[-1]
call_args = call_args[!names(call_args) %in% c("rep","hpc_args")]

content = do.call(ci$create_formula_index, call_args)

df$call(index=content$index, fun=one_item, const=content$const,
rep=rep, result_only=result_only, hpc_args=hpc_args)
}
Expand Down

0 comments on commit 9dae849

Please sign in to comment.