sref: Create a Safer Reference to an Object

Description Usage Arguments Details Examples

View source: R/sref.R

Description

Create a reference to an arbitrary R object. See ref for more details. sref behaves similar to ref, but does not have support for direct operations on the referenced object.

Usage

1
sref(x)

Arguments

x

object to be referenced. x can be a symbol, character, or an expression containing a symbol.

Details

sref is similar to ref; it accepts either an R object or an expression, then records its location. ref objects prioritize convenience, while sref objects prioritize clarity and safety. For example, `[` and `$` can be used on a ref object to access the elements of the underlying object, while `[<-` and `$<-` can be used to overwrite elements within. These do not work for sref objects. Furthermore, base mathematical functions such as `+` and sqrt also will not automatically dereference before applying.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
x <- 1:10
ref_x  <- ref(x)
sref_x <- sref(x)

## These operations will run:
ref_x + 5
ref_x[1:4]
ref_x[7] <- 5

## These operations will not run:
# sref_x + 5
# sref_x[1:4]
# sref_x[7] <- 5

refer documentation built on Nov. 8, 2021, 5:08 p.m.