Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Knitr echo function call with evaluated parameter names

Tags:

r

knitr

If I have previously defined

n <- 200   
maf <- .2 

Is there any way to echo

snp <- rbinom(n,2,maf)

such that it displays as

snp <- rbinom(200,2,.2)

in the resulting knitr document.

like image 402
rdelbel Avatar asked Jun 27 '13 18:06

rdelbel


1 Answers

You can use substitute like this :

```{r ,echo=FALSE}
 substitute(snp <- rbinom(n,2,maf),list(n=n,maf=maf))
 rbinom(n,2,maf)
```

## snp <- rbinom(200, 2, 0.2)
##   [1] 0 0 1 1 1 1 0 0 0 0 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 2 0 1 1 2 1 0 0 0 0
##  [36] 1 0 0 1 0 0 0 0 0 1 0 0 1 0 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 1 1 0 0 1
##  [71] 0 1 0 0 0 0 0 1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 1 1 1 2 0 1 0 1 1 0 1 0 0
## [106] 1 1 0 1 1 1 0 0 1 0 0 0 0 0 0 1 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
## [141] 1 0 0 1 0 0 1 0 2 0 0 0 1 0 0 0 1 1 0 0 0 0 0 2 1 1 2 0 1 0 0 0 0 0 1
## [176] 0 0 2 0 1 1 0 0 0 0 0 1 0 1 2 0 1 1 2 0 0 1 1 1 0
like image 69
agstudy Avatar answered Oct 30 '22 03:10

agstudy