MAJOR=4
MINOR=43
DEVNAME=tty43
 Ý    <!--
%\VignetteEngine{knitr::knitr}
%\VignetteIndexEntry{Templating with knit_expand()}
-->

# Demos of `knit_expand()`

A few simple examples:

```{r}
library(knitr)
knit_expand(text = 'The value of pi is {{pi}}.')
knit_expand(text = 'The value of a is {{a}}, so a + 1 is {{a+1}}.', a = rnorm(1))
knit_expand(text = 'The area of a circle with radius {{r}} is {{pi*r^2}}', r = 5)
```

Any number of variables:

```{r}
knit_expand(text = 'a is {{a}} and b is {{b}}, with my own pi being {{pi}} instead of {{base::pi}}', a=1, b=2, pi=3)
```

Custom delimiter `<% %>`:

```{r}
knit_expand(text = 'I do not like curly braces, so use % with <> instead: a is <% a %>.', a = 8, delim = c("<%", "%>"))
```

The pyexpander delimiter:

```{r}
knit_expand(text = 'hello $(LETTERS[24]) and $(pi)!', delim = c("$(", ")"))
```

Arbitrary R code:

```{r}
knit_expand(text = 'you cannot see the value of x {{x=rnorm(1)}}but it is indeed created: x = {{x}}')
res = knit_expand(text = c(' x | x^2', '{{x=1:5;paste(sprintf("%2d | %3d", x, x^2), collapse = "\n")}}'))
cat(res)
```

The m4 example: <https://en.wikipedia.org/wiki/M4_(computer_language)>

```{r}
res = knit_expand(text = c('{{i=0;h2=function(x){i<<-i+1;sprintf("<h2>%d. %s</h2>", i, x)} }}<html>',
'{{h2("First Section")}}', '{{h2("Second Section")}}', '{{h2("Conclusion")}}', '</html>'))
cat(res)
```

Build regression models based on a template; loop through all variables in `mtcars`:

```{r results='hide'}
src = lapply(names(mtcars)[-1], function(i) {
knit_expand(text=c("# Regression on {{i}}", '```{r lm-{{i}}}', 'lm(mpg~{{i}}, data=mtcars)', '```'))
})
# knit the source
res = knit_child(text = unlist(src))
res = paste('<pre><code>', gsub('^\\s*|\\s*$', '', res), '</code></pre>', sep = '')
```
`r res`
 ?÷     #!/bin/sh
#!/bin/bash

### syslog-ng-debun: syslog debug bundle generator
### Written/Copyright: Gyorgy Pasztor <pasztor@linux.gyakg.u-szeged.hu>, (c) 2014-2016.
### Further enhancements: Janos Szigetvari - jszigetvari at gmail dot com, (c) 2016-2022.
### This software may be used and distributed according to the terms of GNU GPLv2
### http://www.gnu.org/licenses/gpl-2.0.html

unalias -a
LANG=en_US
LC_ALL=C
export LANG LC_ALL

version="0.3.20.20220117"

### Check for "local" variable support
if type local | grep builtin >/dev/null; then
	:
elif type bash >/dev/null; then
	exec bash $0 "$@"
else
	printf "No local variable support on this system\n" >&2
	exit 1
fi

###
### Global defaults
### Do not overwrite them, parameters or distro / OS specific detections will do that if neccessary
###

argv_backup="${@}"
engage=0
os="none"
dist="none"
default_debug_params="-Fedv --enable-core"
default_ldebug_params="-Fev"
default_pcap_params="port 514 or port 601 or port 53"
extras=""
sngallpids=""
wecpid=""
debugpid=none
debugtailpid=none
pcappid=none
tracepids=""
ipconfig="ip addr"
routeconfig () { netstat -nr ; }
netstatnlp () { netstat -nlp ; }
netstatlunp () { netstat -lunp ; }
netstatpunt () { netstat -punt ; }
netstatpn () { netstat -pn ; }
netstatsu="netstat -su"
binprefix=/opt/syslog-ng
absscldirs="/usr/share/syslog-ng/include/scl"
relscldirs="share/include/scl share/syslog-ng/include/scl"
workdir=/tmp
lsof="lsof -p"
no_lsof_fallback() { echo "No lsof in path."; }
pscmd="ps auxwwwwwf"
pseao="ps -eao"
cpiopdL="cpio -pdL"
findL () { find -L "$@" ; }
dfk="df -k"
dfh="df -h"
dfi="df -i"
duks="du -ks"
grepq="fgrep -q"
lddcmd="ldd"
topcmd () { top -b -n 1 -c >"${1}"; }
opensslcmd="openssl"
sed_equivalent_cmd="sed -Ee"
mount=mount
varlimit=1000
myplimit () { echo "Plimit query is not supported on this platform" >&3 ; }
distpkgoffile () { echo "Package file search is not supported (yet) on this platform" >&3 ; }
distpkgstatus () { echo "Package status query is not (yet) supported on this platform" >&3 ; }
selftar="tar cf - ."
gzipcmd="gzip -9"
showdep="dpkg -S"
pcapifparm=-i
w=w
vmstat=vmstat
dmesg=dmesg
timestamp () { date +%s ; }
tcpdumpcmd="tcpdump"
tcpdumpopts="-p -s 1500 -w"
opensslmajor=0
getsyslogpids () { pidof syslog-ng ; }
os_hash_helper () { find . '!'