Skip to contents

Base R6 class for all nemo tools. Subclasses override parse_{table_name}() and tidy_{table_name}() for tables needing custom logic.

Typical use: filter_files() (optional), tidy(), write(); run() chains all three.

Public fields

name

(character(1))
Name of tool.

pkg

(character(1))
Package name tool belongs to (for config lookup).

path

(character(1))
Output directory of tool.

config

(Config())
Config of tool.

written_files

(tibble())
Tibble of files written from self$write().

Methods


Method new()

Create a new Tool object.

Usage

Tool$new(name, pkg, path = NULL, files_tbl = NULL)

Arguments

name

(character(1))
Name of tool.

pkg

(character(1))
Package name tool belongs to (for config lookup).

path

(character(1))
Output directory of tool. If files_tbl is supplied, this is ignored.

files_tbl

(tibble(n))
Tibble of files from list_files_dir().

Returns

(R6::R6Class())
R6 object.


Method print()

Print details about the Tool.

Usage

Tool$print(...)

Arguments

...

(ignored).

Returns

(R6::R6Class())
R6 object invisibly.


Method list_files()

List files matching this tool's patterns.

Usage

Tool$list_files()

Returns

(tibble())
The files tibble of matched files. Always a tibble (possibly zero-row), never NULL.


Method get_globs()

Get this tool's S3 sync globs.

Usage

Tool$get_globs()

Returns

(tibble())
tool, table name and its glob.


Method get_tbls()

Get tidy tibbles after parsing and tidying.

Usage

Tool$get_tbls()

Returns

(tibble() or NULL)
The tbls tibble (with a raw list-column after tidy(keep_raw = TRUE)), or NULL if tidy() wasn't called, matched no files, or run() was used (it streams and keeps nothing).


Method filter_files()

Filter files in given tool directory based on inclusion or exclusion tool_parser names. The result is reflected in the files field.

Usage

Tool$filter_files(include = NULL, exclude = NULL)

Arguments

include

(character(n))
tool_parser names to include (e.g. "tool1_table1").

exclude

(character(n))
tool_parser names to exclude (e.g. "tool1_table3").

Returns

(R6::R6Class())
R6 object invisibly.


Method tidy()

Tidy a list of files. The result is reflected in the tbls field.

Usage

Tool$tidy(keep_raw = FALSE)

Arguments

keep_raw

(logical(1))
Should the raw parsed tibbles be kept in the final output?

Returns

(R6::R6Class())
R6 object invisibly.


Method write()

Write tidy tibbles.

Usage

Tool$write(
  output_dir = ".",
  format = "tsv",
  input_id = NULL,
  output_id = NULL,
  prefix_include = FALSE,
  dbconn = NULL,
  write_metadata = TRUE
)

Arguments

output_dir

(character(1))
Directory path to output tidy files. Ignored if format is db.

format

(character(1))
Format of output.

input_id

(character(1))
Input ID to use for the dataset (e.g. run123).

output_id

(character(1))
Output ID to use for the dataset (e.g. out1).

prefix_include

(logical(1))
If TRUE, prepend an input_prefix column to each tidy table.

dbconn

(DBIConnection)
Database connection object (see DBI::dbConnect).

write_metadata

(logical(1))
If TRUE, write a metadata_<tool>.parquet file. Workflow sets FALSE and writes its own.

Returns

(R6::R6Class())
R6 object invisibly. Results stored in self$written_files (NULL if no files were found).


Method get_metadata()

Get metadata for the tool run.

Usage

Tool$get_metadata(input_id, output_id, output_dir, pkgs = NULL)

Arguments

input_id

(character(1))
Input ID to use for the dataset (e.g. run123).

output_id

(character(1))
Output ID to use for the dataset (e.g. out1).

output_dir

(character(1))
Output directory.

pkgs

(character(n))
Which R packages to extract versions for.

Returns

(tibble())
Single-row tibble with columns input_id, output_id, input_dirs, output_dir, pkg_versions, and files.


Method run()

Filter, tidy, and write files in one step. A no-op if already written; if already tidied, writes the in-memory tables via write() instead of re-parsing.

Usage

Tool$run(
  output_dir = ".",
  format = "tsv",
  input_id = NULL,
  output_id = NULL,
  prefix_include = FALSE,
  dbconn = NULL,
  write_metadata = TRUE,
  include = NULL,
  exclude = NULL
)

Arguments

output_dir

(character(1))
Directory path to output tidy files.

format

(character(1))
Format of output.

input_id

(character(1))
Input ID to use for the dataset (e.g. run123).

output_id

(character(1))
Output ID to use for the dataset (e.g. out1).

prefix_include

(logical(1))
If TRUE, prepend an input_prefix column to each tidy table.

dbconn

(DBIConnection)
Database connection object (see DBI::dbConnect).

write_metadata

(logical(1))
If TRUE, write a metadata_<tool>.parquet file.

include

(character(n))
tool_parser names to include (e.g. "tool1_table1").

exclude

(character(n))
tool_parser names to exclude (e.g. "tool1_table6").

Returns

(R6::R6Class())
R6 object invisibly. Results stored in self$written_files.

Examples

fs::path(tempdir(), letters[1:5]) |>
  fs::file_temp_push() |>
  fs::dir_create()
name <- "tool1"; pkg <- "nemo";
path <- system.file("extdata/tool1", package = "nemo")
toolA <- Tool$new(name = name, pkg = pkg, path = path)
toolA$list_files()
#> # A tibble: 11 × 9
#>    tool_parser  parser bname       size lastmodified        path  pattern prefix
#>    <chr>        <chr>  <chr>      <fs:> <dttm>              <chr> <chr>   <chr> 
#>  1 tool1_table1 table1 sampleA.t…   133 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#>  2 tool1_table2 table2 sampleA.t…    70 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#>  3 tool1_table3 table3 sampleA.t…    83 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#>  4 tool1_table4 table4 sampleA.t…    52 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#>  5 tool1_table6 table6 sampleA.t…   100 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#>  6 tool1_table2 table2 sampleA.t…    47 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#>  7 tool1_table3 table3 sampleA.t…    48 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#>  8 tool1_table4 table4 sampleA.t…    34 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#>  9 tool1_table6 table6 sampleA.t…    78 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#> 10 tool1_table1 table1 sampleA.t…   113 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#> 11 tool1_table1 table1 sampleA.t…    93 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#> # ℹ 1 more variable: prefix_suffix <chr>
toolA$filter_files(exclude = "tool1_table3")
toolA$list_files() # note the exclusion this time
#> # A tibble: 9 × 9
#>   tool_parser  parser bname        size lastmodified        path  pattern prefix
#>   <chr>        <chr>  <chr>       <fs:> <dttm>              <chr> <chr>   <chr> 
#> 1 tool1_table1 table1 sampleA.to…   133 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#> 2 tool1_table2 table2 sampleA.to…    70 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#> 3 tool1_table4 table4 sampleA.to…    52 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#> 4 tool1_table6 table6 sampleA.to…   100 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#> 5 tool1_table2 table2 sampleA.to…    47 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#> 6 tool1_table4 table4 sampleA.to…    34 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#> 7 tool1_table6 table6 sampleA.to…    78 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#> 8 tool1_table1 table1 sampleA.to…   113 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#> 9 tool1_table1 table1 sampleA.to…    93 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#> # ℹ 1 more variable: prefix_suffix <chr>

toolB <- Tool$new(name = name, pkg = pkg, path = path)$
  filter_files(include = "tool1_table1")
toolB$list_files()
#> # A tibble: 3 × 9
#>   tool_parser  parser bname        size lastmodified        path  pattern prefix
#>   <chr>        <chr>  <chr>       <fs:> <dttm>              <chr> <chr>   <chr> 
#> 1 tool1_table1 table1 sampleA.to…   133 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#> 2 tool1_table1 table1 sampleA.to…   113 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#> 3 tool1_table1 table1 sampleA.to…    93 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#> # ℹ 1 more variable: prefix_suffix <chr>
# tidy + write
toolC <- Tool$new(name = name, pkg = pkg, path = path)$
  filter_files(exclude = "tool1_table6")$
  tidy()
toolC$list_files()
#> # A tibble: 9 × 9
#>   tool_parser  parser bname        size lastmodified        path  pattern prefix
#>   <chr>        <chr>  <chr>       <fs:> <dttm>              <chr> <chr>   <chr> 
#> 1 tool1_table1 table1 sampleA.to…   133 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#> 2 tool1_table2 table2 sampleA.to…    70 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#> 3 tool1_table3 table3 sampleA.to…    83 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#> 4 tool1_table4 table4 sampleA.to…    52 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#> 5 tool1_table2 table2 sampleA.to…    47 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#> 6 tool1_table3 table3 sampleA.to…    48 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#> 7 tool1_table4 table4 sampleA.to…    34 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#> 8 tool1_table1 table1 sampleA.to…   113 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#> 9 tool1_table1 table1 sampleA.to…    93 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#> # ℹ 1 more variable: prefix_suffix <chr>
toolC$get_tbls() # note the tidy column
#> # A tibble: 9 × 10
#>   tool_parser  parser bname        size lastmodified        path  pattern prefix
#>   <chr>        <chr>  <chr>       <fs:> <dttm>              <chr> <chr>   <chr> 
#> 1 tool1_table1 table1 sampleA.to…   133 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#> 2 tool1_table2 table2 sampleA.to…    70 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#> 3 tool1_table3 table3 sampleA.to…    83 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#> 4 tool1_table4 table4 sampleA.to…    52 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#> 5 tool1_table2 table2 sampleA.to…    47 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#> 6 tool1_table3 table3 sampleA.to…    48 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#> 7 tool1_table4 table4 sampleA.to…    34 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#> 8 tool1_table1 table1 sampleA.to…   113 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#> 9 tool1_table1 table1 sampleA.to…    93 2026-11-09 07:10:24 /hom… "\\.to… sampl…
#> # ℹ 2 more variables: prefix_suffix <chr>, tidy <list>
dir1 <- fs::file_temp(); dir2 <- fs::file_temp()
toolC$write(output_dir = dir1, format = "parquet", input_id = "run1")
(lfC <- list.files(dir1, full.names = TRUE))
#>  [1] "/tmp/RtmpRY5ahT/a/metadata_tool1.parquet"        
#>  [2] "/tmp/RtmpRY5ahT/a/sampleA_2_tool1_table1.parquet"
#>  [3] "/tmp/RtmpRY5ahT/a/sampleA_2_tool1_table2.parquet"
#>  [4] "/tmp/RtmpRY5ahT/a/sampleA_2_tool1_table3.parquet"
#>  [5] "/tmp/RtmpRY5ahT/a/sampleA_2_tool1_table4.parquet"
#>  [6] "/tmp/RtmpRY5ahT/a/sampleA_3_tool1_table1.parquet"
#>  [7] "/tmp/RtmpRY5ahT/a/sampleA_tool1_table1.parquet"  
#>  [8] "/tmp/RtmpRY5ahT/a/sampleA_tool1_table2.parquet"  
#>  [9] "/tmp/RtmpRY5ahT/a/sampleA_tool1_table3.parquet"  
#> [10] "/tmp/RtmpRY5ahT/a/sampleA_tool1_table4.parquet"  

# run
toolD <- Tool$new(name = name, pkg = pkg, path = path)$
  filter_files(exclude = "tool1_table6")$
  run(output_dir = dir2, format = "parquet", input_id = "run2")
(lfD <- list.files(dir2, full.names = TRUE))
#>  [1] "/tmp/RtmpRY5ahT/b/metadata_tool1.parquet"        
#>  [2] "/tmp/RtmpRY5ahT/b/sampleA_2_tool1_table1.parquet"
#>  [3] "/tmp/RtmpRY5ahT/b/sampleA_2_tool1_table2.parquet"
#>  [4] "/tmp/RtmpRY5ahT/b/sampleA_2_tool1_table3.parquet"
#>  [5] "/tmp/RtmpRY5ahT/b/sampleA_2_tool1_table4.parquet"
#>  [6] "/tmp/RtmpRY5ahT/b/sampleA_3_tool1_table1.parquet"
#>  [7] "/tmp/RtmpRY5ahT/b/sampleA_tool1_table1.parquet"  
#>  [8] "/tmp/RtmpRY5ahT/b/sampleA_tool1_table2.parquet"  
#>  [9] "/tmp/RtmpRY5ahT/b/sampleA_tool1_table3.parquet"  
#> [10] "/tmp/RtmpRY5ahT/b/sampleA_tool1_table4.parquet"