Skip to contents

This function coerces a data frame to an object of the class conc.

Usage

as_conc(x, left = NA, match = NA, right = NA, keep_original = FALSE, ...)

Arguments

x

A data frame.

left

The name of the column in x that contains the left co-text of the concordance. Is is.na(left), then this column is assumed to have the name "left".

match

The name of the column in x that contains the match of the concordance. Is is.na(match), then this column is assumed to have the name "match".

right

The name of the column in x that contains the right co-text of the concordance. Is is.na(right), then this column is assumed to have the name "right".

keep_original

Logical. If the values of left, match or right are not NA, should the original names of those columns be kept in the conc object.

...

Additional arguments.

Value

Object of class conc, a kind of data frame with as its rows the matches and with the following columns:

  • glob_id: Number indicating the position of the match in the overall list of matches.

  • id: Number indicating the position of the match in the list of matches for one specific query.

  • source: Either the filename of the file in which the match was found (in case of the setting as_text = FALSE), or the string '-' (in case of the setting as_text = TRUE).

  • left: The left-hand side co-text of each match.

  • match: The actual match.

  • right: The right-hand side co-text of each match.

It also has additional attributes and methods such as:

An object of class conc can be merged with another by means of merge_conc(). It can be written to file with write_conc() and then read with read_conc(). It is also possible to import concordances created by means other than write_conc() with import_conc().

Examples

(conc_data <- conc('A very small corpus.', '\\w+', as_text = TRUE))
#> Concordance-based data frame (number of observations: 4)
#> idx                                           left|match |right             
#>   1                                               |  A   |very small corpus.
#>   2                                              A| very |small corpus.     
#>   3                                         A very|small |corpus.           
#>   4                                   A very small|corpus|.                 
#> 
#> This data frame has 6 columns:
#>    column
#> 1 glob_id
#> 2      id
#> 3  source
#> 4    left
#> 5   match
#> 6   right
df <- as.data.frame(conc_data)
as_conc(df)
#> Concordance-based data frame (number of observations: 4)
#> idx                                           left|match |right             
#>   1                                               |  A   |very small corpus.
#>   2                                              A| very |small corpus.     
#>   3                                         A very|small |corpus.           
#>   4                                   A very small|corpus|.                 
#> 
#> This data frame has 6 columns:
#>    column
#> 1 glob_id
#> 2      id
#> 3  source
#> 4    left
#> 5   match
#> 6   right