nrelUtilityExt

Missing Axon Utility Functions
nrelUtilityExt

Registered StackHub users may elect to receive email notifications whenever a new package version is released or a comment is posted on the forum.

v1.1.3

Axon functions

antiJoin
antiJoin(a, b, by: null, opts: {})

Returns all rows from a where there are not matching values in b, keeping columns from a only.

antiJoin is one of six SQL-style joins modeled on the two-table verbs in the dplyr R package. For more information, including syntax for by and valid options for opts, see the join documentation.

arity
arity(fn)

Given a function name fn, return the number of arguments the function accepts.

dictToFilter
dictToFilter(d)

Transform the contents of a dict into a string compatible with parseFilter. The resulting filter string matches records with tags that include all the name-value pairs in dict d.

Notes

  1. All simple Axon data types are supported except dateTimes, which have no Axon literal.
  2. Dicts that contain reserved keywords as names, such as "return", will not throw an error but but may cause downstream functions such as parseFilter to fail.
  3. Null values in d will cause parseFilter to fail downstream; use the utility function removeNull as needed to clean the input.
exportFunctions
exportFunctions(funcs, filename)

Exports a grid of functions funcs to a tagged record input/output (TRIO) file filename for reuse elsewhere. If missing, the "io/" prefix and ".trio" suffix are added to filename automatically. See also importFunctions.

Examples

readAll(func).exportFunctions("myFunctions")  >> Writes to `io/myFunctions.trio`
fullJoin
fullJoin(a, b, by: null, opts: {})

Returns all rows and columns from both a and b. Rows in a with no match in b will have missing entries in the columns joined from b, and vice versa.

fullJoin is one of six SQL-style joins modeled on the two-table verbs in the dplyr R package. For more information, including syntax for by and valid options for opts, see the join documentation.

hasAll
hasAll(x, names)

Returns true if x has all the elements in names.

  • For dicts, search by key names
  • For grids, search by column names
hasAny
hasAny(x, names)

Returns true if x has any of the elements in names.

  • For dicts, search by key names
  • For grids, search by column names
importFunctions
importFunctions(filename)

Imports a tagged record input/output (TRIO) file of functions and commits them to the Folio. If missing, the "io/" prefix and ".trio" suffix are added to filename automatically. See also exportFunctions.

Examples

importFunctions("myFunctions")  >> Reads from `io/myFunctions.trio`
in
in(a, b)

Convenience for b.contains(a); see contains.

innerJoin
innerJoin(a, b, by: null, opts: {})

Returns all rows from a where there are matching values in b and all columns from a and b. If there are multiple matches between a and b, all combinations of the matches are returned.

innerJoin is one of six SQL-style joins modeled on the two-table verbs in the dplyr R package. For more information, including syntax for by and valid options for opts, see the join documentation.

intersect
intersect(a, b, checked: true)

Returns the set intersection of two lists or dicts a and b. Behavior for dicts differs by checked:

  • If checked is true, verifies that keys included in both a and b have matching values, and throws an error on mismatch.
  • If checked is false, excludes name-value pairs with matching keys but differing values.

Examples

intersect([1, 2, 3],[2, 3, 4])        >> [2, 3]
intersect({a, b}, {a, c})             >> {a}
intersect({a, b:1}, {a, b:1})         >> {a, b:1}
intersect({a, b:1}, {a, b:2})         >> error
intersect({a, b:1}, {a, b:2}, false)  >> {a}
isNA
isNA(val)

Returns true if val is equal to NA, false otherwise.

isNull
isNull(val)

Returns true if val is null, false otherwise.

leftJoin
leftJoin(a, b, by: null, opts: {})

Returns all rows from a and all columns from a and b. Rows in a with no match in b will have missing entries in the columns joined from b. If there are multiple matches between a and b, all combinations of the matches are returned.

leftJoin is one of six SQL-style joins modeled on the two-table verbs in the dplyr R package. For more information, including syntax for by and valid options for opts, see the join documentation.

outerJoin
outerJoin(a, b, by: null, opts: {})

Alias for fullJoin.

parseRef2
parseRef2(val, checked: true)

Convenience wrapper for parseRef that supports leading "@" without throwing error.

removeNA
removeNA(x)

Removes NA values from list or dict x.

Side effects: may rearrange dict key order.

removeNaN
removeNaN(x)

Removes NaN values from list or dict x.

Side effects: may rearrange dict key order.

removeNull
removeNull(x)

Removes null values from list or dict x.

Side effects: may rearrange dict key order.

removeVal
removeVal(x, val)

Remove any elements from list or dict x that equal val.

Side effects: may rearrange dict key order.

rep
rep(x, times)

Replicate the value x the specified number of times. Returns a list.

Examples

rep(1, 2)               >> [1,1]
rep("A", 3).concat("")  >> "AAA"
replace2
replace2(val, from, to)

Convenience wrapper for replace that also allows processing of URIs or dicts.

  • If val is a string, identical to replace
  • If val is a URI, it is coerced to string, modified, and re-parsed as a URI
  • If val is a dict or list, all its string and URI elements have the replacement applied

For dicts and lists, the string replacement is not recursive. (For instance, the replacement will not reach inside of dicts nested within lists.)

rightJoin
rightJoin(a, b, by: null, opts: {})

Returns all rows from b and all columns from a and b. Rows in b with no match in a will have missing entries in the columns joined from a. If there are multiple matches between a and b, all combinations of the matches are returned.

rightJoin is one of six SQL-style joins modeled on the two-table verbs in the dplyr R package. For more information, including syntax for by and valid options for opts, see the join documentation.

semiJoin
semiJoin(a, b, by: null, opts: {})

Returns all rows from a where there are matching values in b, keeping columns from a only. Differs from innerJoin in that it will never duplicate rows of a.

semiJoin is one of six SQL-style joins modeled on the two-table verbs in the dplyr R package. For more information, including syntax for by and valid options for opts, see the join documentation.

setDiff
setDiff(a, b)

Returns the set difference of two lists or dicts a and b: all elements of a that are not in b.

For dicts, elements for removal are checked by name only. Values are ignored, including for keys mapped to Remove.val.

Examples

setDiff([1, 2, 3],[2, 3, 4])  >> [1]
setDiff({a, b}, {a, c})       >> {b}
setDiff({a, b:1}, {b:2})      >> {a}
setDiff({a, b:1}, {-b})       >> {a}
stringToDict
stringToDict(s)

Converts a string of comma-separated values to a dict using eval. Automatically adds brackets { } if needed.

stringToList
stringToList(s)

Converts a string of comma-separated values to a list using eval. Automatically adds brackets [ ] if needed.

union
union(a, b, checked: true)

Returns the set union of two lists or dicts a and b. Behavior for dicts differs by checked:

  • If checked is true, verifies that keys included in both a and b have matching values, and throws an error on mismatch.
  • If checked is false, values from a override values from b. This is similar to merge(b, a) except that keys not mapped to Remove.val always take precedence.

Examples

union([1, 2, 3],[2, 3, 4])        >> [1, 2, 3, 4]
union({a, b}, {a, c})             >> {a, b, c}
union({a, b}, {-b, c}, false)     >> {a, b, c}
union({a, b:1}, {a, b:1})         >> {a, b:1}
union({a, b:1}, {a, b:2})         >> error
union({a, b:1}, {a, b:2}, false)  >> {a, b:1}
Published by NREL

Packages by NREL

Free packages