attachLocally.Object: Attaches an Object locally to an environment

Description Usage Arguments Value Author(s) See Also Examples

Description

Attaches an Object locally to an environment. By default, the fields of the Object are attached to the parent frame, that is, the calling environment.

Usage

1
2
3
## S3 method for class 'Object'
attachLocally(this, private=FALSE, fields=NULL, excludeFields=NULL, overwrite=TRUE,
  envir=parent.frame(), ...)

Arguments

private

If TRUE, private fields are included, otherwise not. This is only effective if fields==NULL.

fields

A character vector specifying elements to be copied. If NULL, all elements are considered.

excludeFields

A character vector specifying elements not to be copied. This has higher priority than fields.

overwrite

If FALSE, fields that already exists will not be copied.

envir

The environment where fields are copied to.

...

Not used.

Value

Returns (invisibly) a character vector of the fields copied.

Author(s)

Henrik Bengtsson

See Also

*attach() For more information see Object.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
foo <- function(object, arg1="some value", ...) {
  cat("Local objects in foo():\n")
  print(ls())

  attachLocally(object)

  cat("\nLocal objects in foo():\n")
  print(ls())

  for (name in ls()) {
    cat("\nObject '", name, "':\n", sep="")
    print(get(name, inherits=FALSE))
  }
}

a <- "A string"
obj <- Object()
obj$a <- "Another string"
obj$b <- NA
foo(obj)
print(a)

R.oo documentation built on Aug. 26, 2020, 5:13 p.m.