2014-05-12 4 views
1

쉘에서 R 스크립트를 호출하려고합니다.쉘에서 R 스크립트 실행

스크립트는 다음과 같습니다 : 내가 얻을

Rscript scriptName fileName 

: 쉘에서이 스크립트를 호출, 그러나

1 2 1 2 4 
2 4 5 4 2 
1 2 3 4 5 

:

functionName <- function(file1){ 
    args <- commandArgs(trailingOnly = TRUE) 
    print(args) 
    data <- read.table(file(file1),row.names=1,header=FALSE,sep='\t',dec='.')} 


functionName(args[1]) 

내 파일 1과 같은 수의 행이 포함 다음 오류 :

Error in args[1] : object of type 'closure' is not subsettable 
Calls: processGroups -> read.table -> file 
Execution halted 

누구든지이 오류 메시지가 의미하는 것을 설명 할 수 있습니까?

+1

'클로저'가 R의 함수 유형 ('help ("closure") 참조) 인 경우, 즉 데이터 객체가 아닌 경우이 오류 메시지를 이해하는 데 도움이됩니다. – Roland

답변

3

시도 functionName(commandArgs(trailingOnly = TRUE)[1])argsfunctionName에 정의 된 개체가 함수 외부에 "표시"되지 않습니다. 여기서는 args() 내장 함수를 나타냅니다 (?args 참조).