Knitr call echo function call with evaluated parameter names

If I previously defined

n <- 200 maf <- .2 

Is there any way to echo

 snp <- rbinom(n,2,maf) 

so that it displays as

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

in the resulting knitr document.

+6
source share
1 answer

You can use substitute as follows:

 ```{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 
+2
source

Source: https://habr.com/ru/post/948264/


All Articles