Computer Science/R
Arguments in R
바닐라스카이
2018. 7. 25. 09:44
반응형
Arguments in R
Rscript를 사용할 때 argument를 input으로 받는 방법.
args = commandArgs(trailingOnly=TRUE)
species <- args[1]
inputfile <= args[2]
Rsciprt test.R human hg19.fasta
argument를 더 복잡하게 쓰려면 optparse라는 라이브러리를 써도 되지만 간단하게 정리하고 싶다면 위와 같이 작성할 수 있다.
추가로 argument를 입력하지 않았을 때 간단한 설명을 넣고 싶다면 아래와 같이 하면 된다.
if(length(args)==0 {
stop("All argument must be supplied ex) human hg19.fasta",call.=FALSE))
}
argument가 하나도 들어오지 않았다면 ERROR 메세지 뒤에 정해놓은 문자열을 출력하고 자동 종료된다.
반응형