File: highr-internals.R

package info (click to toggle)
r-cran-highr 0.10%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 172 kB
  • sloc: sh: 10; makefile: 7
file content (42 lines) | stat: -rw-r--r-- 1,608 bytes parent folder | download
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
## -----------------------------------------------------------------------------
p = parse(text = "   xx = 1 + 1  # a comment", keep.source = TRUE)
(d = getParseData(p))

## -----------------------------------------------------------------------------
(d = d[d$terminal, ])

## -----------------------------------------------------------------------------
head(highr:::cmd_latex)
tail(highr:::cmd_html)

## -----------------------------------------------------------------------------
d$token
rownames(highr:::cmd_latex)

## -----------------------------------------------------------------------------
(z = d[, c('col1', 'col2')])  # take out the column positions
(z = t(z)) # transpose the matrix
(z = c(z)) # turn it into a vector
(z = c(0, head(z, -1))) # append 0 in the beginning, and remove the last element
(z = matrix(z, ncol = 2, byrow = TRUE))

## -----------------------------------------------------------------------------
(s = z[, 2] - z[, 1] - 1)
(s = strrep(' ', s))
paste(s, d$text, sep = '')

## -----------------------------------------------------------------------------
m = highr:::cmd_latex[d$token, ]
cbind(d, m)
# use standard markup if tokens do not exist in the table
m[is.na(m[, 1]), ] = highr:::cmd_latex['STANDARD', ]
paste(s, m[, 1], d$text, m[, 2], sep = '', collapse = '')

## -----------------------------------------------------------------------------
d = getParseData(parse(text = "x = \"a character\nstring\" #hi", keep.source = TRUE))
(d = d[d$terminal, ])

## -----------------------------------------------------------------------------
d$line1[d$line1 == 1] = 2
d