latex - using source("X.R") in Sweave file -


i need use function in sweave file execute chunk codes. example, have function mean <- function(x) mean(x) in directory, want use chunk code

x=c(1,2,3,4) mean(x) 

in sweave file. know how can that?

thanks.

when writing code inside code blocks of document, make sure set directory of r file located , source file.

e.g.,

<<echo=true>>=     setwd(mydirectory)     source(myfile)     print(mean(x)) @