Turns a vector of export paths into one row of design information per
file: the directory levels below root, the file-name markers, the
replicate index and the grammar tokens.
Usage
cr_parse_paths(
paths,
root = NULL,
levels = NULL,
grammar = NULL,
markers = NULL,
strict = TRUE,
spec = NULL,
call = rlang::caller_env()
)Arguments
- paths
Character vector of file paths.
- root
Directory the paths sit under. Required when
levelsis given.- levels
Directory level specification; see
cr_path_spec().- grammar
A
cr_filename_grammar(), orNULL.- markers
A
cr_marker_rules()object, orNULL.- strict
Logical. Abort on an unparseable file name. When
specis supplied andstrictis not, the spec's setting is used.- spec
Optional
cr_path_spec()supplying any oflevels,grammar,markersandstrictthat are not given directly.- call
The execution environment of the calling function. Used for error reporting; experts only.
Value
A tibble with one row per path: source_file, source_path,
one column per directory level, the marker flag columns, variant,
core, replicate, one column per grammar token, and the
parse_ok / parse_error outcome.
Details
With strict = TRUE (the default) a file name that matches no
core_patterns entry of the grammar aborts the parse. That is the
intended behaviour: a name that parses to defaults instead of failing
loudly can move a treated unit into a control arm without anything in
the analysis noticing.
See also
cr_path_spec(), cr_filename_grammar(),
cr_marker_rules(), cr_read_exports().
Other import:
cr_assign_units(),
cr_centroid_overlap(),
cr_column_map(),
cr_extract_markers(),
cr_filename_grammar(),
cr_marker_rules(),
cr_merge_rules(),
cr_path_spec(),
cr_read_cellprofiler(),
cr_read_cells(),
cr_read_design(),
cr_read_export(),
cr_read_exports(),
cr_read_qupath(),
cr_read_segmantr(),
cr_unit_map()
Examples
root <- file.path(tempdir(), "cr_paths_demo")
paths <- file.path(
root, "Run1", "CompoundA", "Plate_1",
c("CompoundA_vehicle_1.csv", "CompoundA_5min_10uM_treated_1.csv")
)
cr_parse_paths(
paths,
root = root,
levels = c("run", "compound", "plate"),
grammar = cr_filename_grammar(
tokens = list(interval = "[0-9]+min", dose = "[0-9]+uM"),
defaults = list(interval = "none", dose = "vehicle"),
prefix_strip = "CompoundA"
)
)
#> # A tibble: 2 × 17
#> source_file source_path run compound plate merge_unit partial_plate
#> <chr> <chr> <chr> <chr> <chr> <lgl> <lgl>
#> 1 CompoundA_vehicle_1… /tmp/Rtmpb… Run1 Compoun… Plat… FALSE FALSE
#> 2 CompoundA_5min_10uM… /tmp/Rtmpb… Run1 Compoun… Plat… FALSE FALSE
#> # ℹ 10 more variables: omitted_reagent <lgl>, reacquisition <lgl>, lot <lgl>,
#> # variant <chr>, core <chr>, replicate <chr>, interval <chr>, dose <chr>,
#> # parse_ok <lgl>, parse_error <chr>