Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
55 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#' Split indices. | ||
#' An optimised version of split for the special case of splitting row | ||
#' indices into groups, as used by \code{\link{splitter_d}} | ||
#' | ||
#' @param index integer indices | ||
#' @param group integer groups | ||
#' @param n largest integer (may not appear in index) | ||
#' @useDynLib plyr | ||
#' @keywords internal manip | ||
loop_apply <- function(n, f, env = parent.frame()) { | ||
.Call("loop_apply", as.integer(n), f, env) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <R.h> | ||
#include <Rdefines.h> | ||
|
||
SEXP loop_apply(SEXP n, SEXP f, SEXP rho) { | ||
if(!isFunction(f)) error("'f' must be a function"); | ||
if(!isEnvironment(rho)) error("'rho' should be an environment"); | ||
|
||
int n1 = INTEGER(n)[0]; | ||
|
||
SEXP results, R_fcall; | ||
PROTECT(results = allocVector(VECSXP, n1)); | ||
PROTECT(R_fcall = lang2(f, R_NilValue)); | ||
|
||
SEXP ii; | ||
for(int i = 0; i < n1; i++) { | ||
ii = PROTECT(ScalarInteger(i + 1)); | ||
SETCADR(R_fcall, ii); | ||
SET_VECTOR_ELT(results, i, eval(R_fcall, rho)); | ||
|
||
UNPROTECT(1); | ||
} | ||
|
||
UNPROTECT(2); | ||
return results; | ||
} |