Learn R Programming

rock (version 0.8.1)

sync_streams: Synchronize multiple streams

Description

This function maps the codes from multiple streams onto a primary stream.

Usage

sync_streams(
  x,
  primaryStream,
  columns = NULL,
  anchorsCol = rock::opts$get("anchorsCol"),
  sourceId = rock::opts$get("sourceId"),
  streamId = rock::opts$get("streamId"),
  prependStreamIdToColName = FALSE,
  appendStreamIdToColName = FALSE,
  sep = " ",
  fill = TRUE,
  compressFun = NULL,
  compressFunPart = NULL,
  expandFun = NULL,
  colNameGlue = rock::opts$get("colNameGlue"),
  silent = rock::opts$get("silent")
)

Value

The object with parsd sources, x, with the synchronization results added in the $syncResults subobject.

Arguments

x

The object with the parsed sources.

primaryStream

The identifier of the primary stream.

columns

The names of the column(s) to synchronize.

anchorsCol

The column containing the anchors.

sourceId

The column containing the source identifiers.

streamId

The column containing the stream identifiers.

prependStreamIdToColName, appendStreamIdToColName

Whether to append or prepend the stream identifier before merging the dataframes together.

sep

When not specifying compressFun and compressFunPart, the paste function is used to combine elements, and in that case, sep is passed to paste as separator.

fill

When expanding streams, whether to duplicate elements to fill the resulting vector. Ignored if fillFun is specified.

compressFun

If specified, when compressing streams, instead of pasting elements together using separator sep, the vectors are passed to function compressFun, which must accept a vector (to compress) and a single integer (with the desired resulting length of the vector).

compressFunPart

A function to apply to the segments that are automatically created; this can be passed instead of compressFun.

expandFun

If specified, when expanding streams, instead of potentially filling the new larger vector with elements (if fill is TRUE), the vectors are passed to function expandFun, which must accept a vector (to compress) and a single integer (with the desired resulting length of the vector).

colNameGlue

When appending or prepending stream identifiers, the character(s) to use as "glue" or separator.

silent

Whether to be silent (TRUE) or chatty (FALSE).

Examples

Run this code
### Get a directory with example sources
examplePath <-
  file.path(
    system.file(package="rock"),
    'extdata',
    'streams'
  );

### Parse the sources
parsedSources <- rock::parse_sources(
  examplePath
);

### Add a dataframe, syncing all streams to primary stream !
parsedSources <- rock::sync_streams(
  parsedSources,
  primaryStream = "streamA",
  columns = c("Code1", "Code2", "Code3"),
  prependStreamIdToColName = TRUE
);

### Look at two examples
parsedSources$syncResults$mergedSourceDf[
  ,
  c("streamB_Code3", "streamC_Code1")
];

Run the code above in your browser using DataLab