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")
)
The object with the parsed sources.
The identifier of the primary stream.
The names of the column(s) to synchronize.
The column containing the anchors.
The column containing the source identifiers.
The column containing the stream identifiers.
Whether to append or prepend the stream identifier before merging the dataframes together.
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.
When expanding streams, whether to duplicate elements to fill
the resulting vector. Ignored if fillFun
is specified.
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).
A function to apply to the segments that are
automatically created; this can be passed instead of compressFun
.
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).
When appending or prepending stream identifiers, the character(s) to use as "glue" or separator.
Whether to be silent (TRUE
) or chatty (FALSE
).
The object with parsd sources, x
, with the synchronization results
added in the $syncResults
subobject.
### 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