Learn R Programming

nws (version 1.6.2)

nwsIFindTry: netWorkSpace Class Method

Description

Create a function that acts as a non-destructive iterator over the values of the specified variable.

Usage

## S3 method for class 'netWorkSpace':
nwsIFindTry(.Object, xName, defaultVal=NULL)

Arguments

.Object
a netWorkSpace class object
xName
name of the variable to be fetched
defaultVal
value to return, if xName is not found in the netWorkSpace

Details

The iterator function returned by the nwsIFindTry method takes no arguments, and works somewhat like the nwsFindTry method, specified with the same arguments that were passed to nwsIFindTry. The difference is that the nwsFindTry method cannot iterate through the values of a variable; it always returns the same value until the variable is modified. The iterator function, however, maintains some state that allows it to see subsequent values. Each time the iterator function is called, it returns the next value in the variable. Once all values in the variable have been returned, the iterator function will return defaultVal. However, when new values are stored into the variable, the iterator function will return them, picking right up where it left off.

See Also

nwsFindTry, nwsIFind

Examples

Run this code
ws <- netWorkSpace('nws example')
nwsStore(ws, 'x', 1)
nwsStore(ws, 'x', 2)
it <- nwsIFindTry(ws, 'x', NA)
it()  # returns the value 1
it()  # returns the value 2
it()  # returns the value NA
nwsStore(ws, 'x', 3)
it()  # returns the value 3
it()  # returns the value NA

Run the code above in your browser using DataLab