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

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")
)

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).

Value

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

Examples

### 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")
];
#>    streamB_Code3 streamC_Code1
#> 1              0             0
#> 2              0             0
#> 3              1             0
#> 4              1             0
#> 5              0             0
#> 6              0             1
#> 7            1 1           0 0
#> 8              0           0 0
#> 9              0         0 1 0
#> 10             0             0
#> 11             0           0 1
#> 12             0             0
#> 13             0             0
#> 14             0           0 1
#> 15           0 0           0 0
#> 16             0             0
#> 17             0             0
#> 18             0             1
#> 19             0           0 1
#> 20             0             0
#> 21             1           0 1
#> 22             0             0
#> 23             1             0
#> 24             0             0