2013-09-02 2 views
1

요약에 R 계산을 포함시키고 싶습니다. R 계산은 문서 맨 아래에 있으므로 rnw 파일을 컴파일하면 오류가 발생합니다.기사에서 R 계산 사용 요약

여기에 최소한의 예입니다

\documentclass{article} 
\begin{document} 

\begin{abstract} 
    This paper... and we got a mean of \Sexpr{mean.data}. 
\end{abstract} 

<<>>= 
data <- c(1,2,3,4,5) 
mean.data <- mean(data) 
@ 

\end{document} 
+0

현재 knitr은 코드 덩어리와 인라인 표현식을 선형 방식으로 실행하므로 "미래의"객체를 사용할 수 없습니다. 캐시 데이터베이스가 존재하는 경우 향후 캐시에서 개체를로드 할 수 있도록 무언가를 제공 할 수도 있습니다. –

답변

1

초록 뒤에 계산이 필요하면 결과를 파일에 저장하고 초록으로로드 할 수 있습니다. LaTeX 파일을 두 번 컴파일해야합니다.

\documentclass{article} 
\begin{document} 

\begin{abstract} 
This paper... and we got a mean of \Sexpr{load("a.RData"); mean.data}. 
\end{abstract} 

<<Computations>>= 
data <- c(1,2,3,4,5) 
mean.data <- mean(data) 
save(mean.data, file="a.RData") 
@ 

\end{document} 
+0

감사합니다. – wipeout

5

그럼 당신 분명히이되지 후, 사용하기 전에 뭔가의 정의을 사용하는 이동해야합니다. 그래서 그 대신이 시도 :

\documentclass{article} 
\begin{document} 

<<>>= 
data <- c(1,2,3,4,5) 
mean.data <- mean(data) 
@ 

\begin{abstract} 
    This paper... and we got a mean of \Sexpr{mean.data}. 
\end{abstract} 

\end{document} 

덩어리는\begin{document} 전에 을 포함하여 거의 모든 곳에서 발생할 수 있습니다.

0

LaTeX를 사용하는 경우 대체 방법은 LaTeX 처리 단계에서 출력 순서를 재정렬하는 것입니다. 나는 somewhat similar question on the TeX stack exchange site에게 물었다.

이 접근법은 filecontents (LaTeX) 패키지를 사용하여 출력의 일부를 저장 한 다음 나중에 재생합니다. 이 접근 방식에서는 실제로 문서의 끝 부분에 초록이 정의되지만, 그 위에있는 모든 것은 파일에 저장되고 LaTeX 처리 단계에서 초록 이후에 다시 삽입됩니다.