File: utils.R

package info (click to toggle)
r-cran-nlp 0.3-2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 456 kB
  • sloc: makefile: 2
file content (46 lines) | stat: -rw-r--r-- 814 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
### Format and print.

.format_TextDocument <-
function(x, ...)
    c(sprintf("<<%s>>", class(x)[1L]),
      sprintf("Metadata:  %d", length(meta(x))))

.print_via_format <-
function(x, ...) 
{
    writeLines(format(x, ...))
    invisible(x)
}

### Get and set metadata.

.get_meta_if_attr <-
function(x, tag = NULL, ...)
{
    m <- attr(x, "meta")
    if(is.null(tag)) m else m[[tag]]
}

.set_meta_if_attr <-
function(x, tag = NULL, ..., value)    
{
    if(is.null(tag))
        attr(x, "meta") <- value
    else
        attr(x, "meta")[[tag]] <- value
    x
}

.get_meta_if_slot <-
function(x, tag = NULL, ...)
    if(is.null(tag)) x$meta else x$meta[[tag]]

.set_meta_if_slot <-
function(x, tag = NULL, ..., value)
{
    if(is.null(tag))
        x$meta <- value
    else
        x$meta[[tag]] <- value
    x
}