더북(TheBook)

R에서 도움말은 ‘?’ 뒤에 찾고자 하는 명령을 입력하거나 ‘help(명령)’ 형태로 입력하여 볼 수 있다. 예를 들어, 앞서 사용한 print 함수에 대한 도움말은 다음과 같이 볼 수 있다.

> ?print
print           package:base           R Documentation

Print Values

Description:
        'print' prints its argument and returns it _invisibly_ (via
        'invisible(x)'). It is a generic function which means that new  
        printing methods can be easily added for new 'class'es.

Usage:

        print(x, ...)   

        ## S3 method for class 'factor' 
        print(x, quote = FALSE, max.levels = NULL,
                width = getOption("width"), ...)

        ## S3 method for class 'table'
        print(x, digits = getOption("digits"), quote = FALSE,   
                na.print = "", zero.print = "0", justify = "none", ...)

        ## S3 method for class 'function'

...

Examples:

        require(stats)

        ts(1:20) #-- print is the "Default function" --> print.ts(.) is called       
        for(i in 1:3) print(1:i)

        ## Printing of factors  
        attenu$station ## 117 levels -> 'max.levels' depending on width      

        ## ordered factors: levels "l1 < l2 < .." 
        esoph$agegp[1:12]
        esoph$alcgp[1:12]       

        ## Printing of sparse (contingency) tables      
        set.seed(521)   
        t1 <- round(abs(rt(200, df = 1.8)))  
        t2 <- round(abs(rt(200, df = 1.4)))  
        table(t1, t2) # simple
        print(table(t1, t2), zero.print = ".") # nicer to read  

        ## Corner cases with empty extents:     
        table(1, NA) # < table of extent 1 x 0 >

윈도우에서는 브라우저에서 곧바로 도움말이 표시되지만 리눅스에서는 한 화면만큼만 도움말이 출력된 뒤 ‘:’이 표시되면서 다음 입력을 기다린다. 이 프롬프트는 리눅스의 less 명령과 같은 방식으로 사용할 수 있다. 엔터 키를 눌러 다음 행을 보거나, 스페이스를 눌러 다음 페이지를 볼 수 있다. b를 누르면 이전 페이지가 보이며, q를 누르면 도움말 화면을 빠져나간다.

도움말에서는 위와 같이 예제(‘Examples’ 섹션)가 포함된 경우가 많다. 예제는 ‘example(함수명)’을 사용해 쉽게 실행해볼 수 있다. 예를 들어, print()에 대한 예제는 example(print)를 입력하면 실행할 수 있다.

신간 소식 구독하기
뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.