pd_class_definitions: Test for Class Definitions

Description Usage Arguments Format Details Examples

Description

These function manage adding class defining functions and testing if an id is associated with a class definition or if is contained in the class definition.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
pd_class_definitions

pd_is_class_definition(id, pd, .check = TRUE)

pd_is_in_class_definition(id, pd, .check = TRUE)

pd_add_class_definition(
  name,
  test.is,
  test.in,
  .exists = TRUE,
  .overwrite = FALSE
)

pd_add_class(name, .exists = TRUE, .overwrite = FALSE)

Arguments

id

id(s) to test.

pd

parse data which contains id.

.check

should the id, and pd be checked?

name

name of the class defining function

test.is

function accepting arguments id and pd which tests if given id is associated with the defined class defining functions.

test.in

function accepting arguments id and pd which tests if given id is contained in the defined class defining functions.

.exists

require the function to exists to add.

.overwrite

if TRUE allows for overwriting existing test functions.

Format

An object of class environment of length 12.

Details

pd_class_definitions$has

Usage
1
2

Check if a class defining function has 'is' and 'in' function defined for it.

pd_class_definitions$add or pd_add_class

Usage
1
2
3
pd_class_definitions$add(name, .exists=TRUE, .overwrite=FALSE)

pd_add_class(name, .exists=TRUE, .overwrite=FALSE)

Add a def with default 'is' and 'in' functions defined.

pd_class_definitions$add_definition or pd_add_class_definition

Usage
1
2
3
pd_class_definitions$add_definition(name, test.is, test.in, .exists=TRUE, .overwrite=FALSE)

pd_add_class_definition(name, test.is, test.in, .exists=TRUE, .overwrite=FALSE)

Add a class defining function with custom 'is' and 'in' functions defined.

pd_class_definitions$rm

Usage
1

Remove the testing functions for the class.

pd_class_definitions$names

Usage
1

Return a vector of the classed for which tests are defined.

pd_class_definitions$test_is

Usage
1
pd_class_definitions$test_is(id, pd, check=TRUE)

Test if id is associated with each of defined class definitions.

pd_class_definitions$test_is_in

Usage
1
pd_class_definitions$test_is_in(id, pd, check=TRUE)

Test if id is contained within each of defined class definitions.

pd_class_definitions$which

Usage
1

Return the name of the class, if any, which id corresponds to.

pd_class_definitions$in_which

Usage
1
pd_class_definitions$in_which(id, pd, check=TRUE)

Returns a vector of the classes, if any, of the classes which id is contained in.

pd_is_class_definition

Returns TRUE if the id corresponds to any of the class defining calls.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# load example file and get_parse data
ex.file <- system.file("examples", "example.R", package="parsetools")
exprs <- parse(ex.file, keep.source = TRUE)
pd <- get_parse_data(exprs)

# There are 3 expressions so there should be three roots.
sum(pd_is_root(pd$id, pd))
roots <- pd_all_root_ids(pd)

# Get the 'setClass' call.
class.id <- pd_get_assign_value_id(roots[2], pd)
# Check to make sure that it is a function that sets a class.
pd_is_class_definition(class.id, pd)
# and that it is the setClass call.
pd_text(pd_get_call_symbol_id(class.id, pd), pd)

parsetools documentation built on April 14, 2020, 5:32 p.m.