Package: nc 2026.4.20

nc: Named Capture to Data Tables

User-friendly functions for extracting a data table (row for each match, column for each group) from non-tabular text data using regular expressions, and for melting columns that match a regular expression. Patterns are defined using a readable syntax that makes it easy to build complex patterns in terms of simpler, re-usable sub-patterns. Named R arguments are translated to column names in the output; capture groups without names are used internally in order to provide a standard interface to three regular expression 'C' libraries ('PCRE', 'RE2', 'ICU'). Output can also include numeric columns via user-specified type conversion functions.

Authors:Toby Hocking [aut, cre]

nc_2026.4.20.tar.gz
nc_2026.4.20.zip(r-4.7)nc_2026.4.20.zip(r-4.6)nc_2026.4.20.zip(r-4.5)
nc_2026.4.20.tgz(r-4.6-any)nc_2026.4.20.tgz(r-4.5-any)
nc_2026.4.20.tar.gz(r-4.7-any)nc_2026.4.20.tar.gz(r-4.6-any)
nc_2026.4.20.tgz(r-4.6-emscripten)
manual.pdf |manual.html
DESCRIPTION |NEWS
card.svg |card.png
nc/json (API)

# Install 'nc' in R:
install.packages('nc', repos = c('https://tdhock.r-universe.dev', 'https://cloud.r-project.org'))

Bug tracker:https://github.com/tdhock/nc/issues

On CRAN:

Conda:

6.75 score 19 stars 1 packages 62 scripts 725 downloads 17 exports 1 dependencies

Last updated from:1b6891de2c. Checks:9 OK. Indexed: yes.

TargetResultTimeFilesSyslog
linux-devel-x86_64OK154
source / vignettesOK241
linux-release-x86_64OK191
macos-release-arm64OK124
macos-oldrel-arm64OK81
windows-develOK101
windows-releaseOK106
windows-oldrelOK125
wasm-releaseOK135

Exports:alevelsalternativesalternatives_with_shared_groupsaltlistbefore_matchcapture_all_strcapture_first_dfcapture_first_globcapture_first_veccapture_longer_speccapture_melt_multiplecapture_melt_singlefieldgroupmeasurequantifiervar_args_list

Dependencies:data.table

Uniform interface to three regex engines

Last update: 2026-02-21
Started: 2021-05-11

Helper functions
nc::field for reducing repetition | nc::quantifier for fewer parentheses | nc::alternatives for simplified alternation | nc::alternatives_with_shared_groups for alternatives with identical named sub-pattern groups

Last update: 2024-09-20
Started: 2021-05-11

Overview of nc functionality
Capture first match in several subjects | Capture all matches in a single subject | Reshape a data table with regularly named columns | Reading regularly named data files | Helper functions for defining complex pattterns

Last update: 2024-09-20
Started: 2021-05-11

Reading regularly named files
Example 0: iris data, one file per species | Example 1: four files, two capture groups, custom read function | Why not base R? | Example 3: Hive partition file names | Example 4: pattern with two more capture groups | Example 5: parsing non-CSV data | Conclusion

Last update: 2024-08-27
Started: 2024-01-05

Capture all matches in a single subject string
Match all tracks in the text file | Match all fields in each track | Match all tracks and some fields with one regex | Parsing SweeD output files

Last update: 2024-03-31
Started: 2019-09-04

Capture first match
Capture first match in each character vector element | View generated regex | Error/NA if any subjects do not match | Other regex engines | Capture first match from one or more character columns in a table | Complex example: fsa file names

Last update: 2024-03-31
Started: 2019-09-04

Capture melt
Reshaping several input columns into a single output column | Reshaping several input columns into multiple output columns | Melting WHO data with a more complex pattern | Melting monthly Eurostat data | Melting into multiple output columns with missing input columns | Multiple output columns of different types

Last update: 2024-03-31
Started: 2019-10-25

Comparisons with other packages
Are sepals larger or smaller than petals in the iris data? | Comparing dimensions in iris data | Do columns need to be sorted? | Melting into a single output column, who data | Melting a wider iris back to original | Lots of column types | family data | histogram of iris | single output column simple type conversion | Multiple output columns of different types

Last update: 2024-03-31
Started: 2019-10-25

Readme and manuals

Help Manual

Help pageTopics
Alternative levelsalevels
alternativesalternatives
alternatives with shared groupsalternatives_with_shared_groups
altlistaltlist
apply type funsapply_type_funs
before matchbefore_match
Capture all matches in a single subject stringcapture_all_str
Capture first match in columns of a data framecapture_first_df
capture first globcapture_first_glob
Capture first match in each character vector elementcapture_first_vec nc
capture longer speccapture_longer_spec
Capture and melt into multiple columnscapture_melt_multiple
Capture and melt into a single columncapture_melt_single
check df namescheck_df_names
check namescheck_names
collapse somecollapse_some
Capture a fieldfield
Capture groupgroup
measuremeasure
measure multiplemeasure_multiple
measure singlemeasure_single
melt listmelt_list
only capturesonly_captures
quantifierquantifier
stop for capture same as idstop_for_capture_same_as_id
stop for enginestop_for_engine
stop for subjectstop_for_subject
subject var argssubject_var_args
try or stop print patterntry_or_stop_print_pattern
var args listvar_args_list