create_instance: Create instance object

Description Usage Arguments Details Author(s) References See Also Examples

Description

Convenience wrapper around 'structure()'.

Usage

1

Arguments

of

character. Name of the class for which an instance should be created.

with

ANY. Any object that should act as the actual data of the instance.

inherits

logical. TRUE: resulting object inherits from class(es) of with. FALSE (default): resulting object only has class of.

attributes

list Attributes to be passed along to the instance. Supply as a named list.

Details

None yet.

Author(s)

Janko Thyson janko.thyson@gmail.com

References

http://github.com/rappster/instancer

See Also

TODO

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Intro -------------------------------------------------------------------

create_instance(of = "test_class")
create_instance(of = "test_class", with = letters[1:3])
create_instance(of = "test_class", with = letters[1:3], inherits = FALSE)

# Additional attributes ---------------------------------------------------

create_instance(of = "test_class", with = letters[1:3],
  attributes = list(attr_1 = TRUE, attr_2 = "yep!"))
create_instance(of = "test_class", with = letters[1:3],
  attributes = list(my_attrs = list(attr_1 = TRUE, attr_2 = "yep!")))

# Preserve data frames ----------------------------------------------------

# A data frame is automatically "reduced" to its list structure if no
# inheritance is involved
structure(mtcars, class = "test_class")

# Therefore it seems to be best to throw an error in case the user wants to try
# this in order to make it explicit to chose a list input if that's what he
# wants
create_instance(of = "test_class", with = mtcars, inherits = FALSE)
create_instance(of = "test_class", with = unclass(mtcars), inherits = FALSE)

rappster/instancer documentation built on May 26, 2019, 11:17 p.m.