Learn R Programming

rtape (version 2.2)

rtapeFilter: Rerecord the tape dropping certain objects.

Description

Rerecord the tape dropping certain objects.

Usage

rtapeFilter(FUN, fNamesIn, fNameOut=fNamesIn, moreArgs, fileFormatOut=guessFileFormat(fNameOut))

Arguments

FUN
Callback function which gets the current object and returns a boolean value that directs rtape to either keep (for TRUE) or discard it.
fNamesIn
Name of the tape file to read; if this argument is a vector of several names, function behaves as reading a single tape made of all those tapes joined in a given order.
fNameOut
Name of the tape to which store the output of filtering; if this file is one of the input files, this file is overwritten with the output; otherwise the output is appended to this tape. This must be a one-element vector.
moreArgs
Additional arguments to FUN, given as a list.
fileFormatOut
File format; should be left default. See guessFileFormat and makeFileFormat for details.

Details

This function reads the objects from one tape, executes a callback function on them and leaves/appends to the other tape only those for which callback returned TRUE.

Examples

Run this code
#Record something
for(i in 1:10) rtapeAdd('tmp.tape',i)

#Discard even numbers
rtapeFilter(function(x) (x%%2)==1,'tmp.tape')

#Check it out
unlist(rtapeAsList('tmp.tape'))->A
print(A);
stopifnot(all(A==c(1,3,5,7,9)))

#Time to clean up
unlink(c('tmp.tape'))

Run the code above in your browser using DataLab