Description Usage Arguments Value Examples
Similar to well-know lapply, but returns only the last result as an object. Very usefull when working with big datasets. If the object to be returned is large in memory, say it contains copies of a large dataset, iapply iteratively applies a function but returns only the last output of the function application. This is useful if the function prints diagnostics to screen or saves results in a log file, but you would like to evaluate the last object to understand the output better. Additionally, the function allows you to write all the output to disk using a Serialization Interface for Single Objects. This allows you to restore any output to an object, possibly with a different name.
1 2 |
X |
a vector of input variables similar to lapply. |
FUN |
a function to be applied iteratively over the input arguments. similar to FUN in lapply. |
writedisk |
TRUE/FALSE indicating whether output of application of FUN to elements of X should be written to disk as serialized representions in RDS files before it gets overwritten in memory. Will also write the final output to disk. |
outdir |
output directory where .RDS files should be written. |
name |
When writedisk = TRUE, output is saved with this name followed by the iteration. By default, uses getCall2(), thus RDS files are "iapply" followed by the number of th element. However storing iapply in another object, will change the output name. |
compress |
a logical specifying whether outputted RDS files use "gzip" compress, or one of "gzip", "bzip2" or "xz" to indicate the type of compress to be used. Defaults to no compress. You can later restore the objects using readRDS(). |
the output of FUN(X[X[length(X)]], plus any prints, messages, warnings, errors that lapply(X, FUN) would produce. If FUN writes results to a disk, these files will be created too.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | f <- function(x){
print (x)
return(x)
}
x=1:10
# this will print all elements of x, finaloutput will only contain the last element of x.
finaloutput <- iapply (x, f)
print(finaloutput)
# this will print all elements of x, create 10 RDS files that you can use to restore f(x),
# finaloutput will contain the last element of x.
finaloutput <- iapply (x, f, writedisk = TRUE, outdir = "C:\\Users\\")
print(finaloutput)
# this will do the same, but stores names as "binomials1", "binomials2" etc.
binomials <- iapply
finaloutput <- binomials (x, f, writedisk = TRUE, outdir = "C:\\Users\\")
print(finaloutput)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.