About me | pbdR Tech | HPSC | Phyloclustering | R_note |

R_note -- The Exploration of Statistical Software R (統計軟體 R 深度歷險)
About R_note
Reference
MS Windows

Batch jobs
Function
Data/MySQL
Plot
String/Parse

Remark Lines
Classes/S3
S4 Methods
Batch more
Environment

Good Coding
Fast Loop
LAM/MPI/Rmpi
Recursion

PHP Call R
Basic C
R Call Fortran/C
R Call GSL
C Call R API
C Call R Objects
Standalone

Make Packages
C Pointer
Debug




Section: Function

  • Conclusion
    There are two conclusions for this page.
    R uses "Pass by value".
    R uses "Default initialize".

  • Function 1
    First, create an R code file "func_1.r" contains this, run it and trace the result to see the difference.

        
    # File name: func_1.r
    
    hello <- function(input){
      a <- c("Hello", "world", input, "!")
      input <- NULL
      molas <- "molas"
      ret <- paste(a, collapse = " ")
      ret
    }
    
    molas <- "MOLAS"
    input <- c("again,", molas)
    input
    hello(input)
    molas
    input
    hello()
    hello(NULL)
    

  • Function 2
    First, create an R code file "func_2.r" contains this, run it and trace the result to see the difference.

        
    # File name: func_2.r
    
    hello <- function(a, ...){
      ret <- paste(a, ...)
      ret
    }
    
    test <- function(input = "molas") {
      a <- c("Hello", "world", input, "!")
      input <- NULL
      molas <- "molas"
      ret <- hello(a, collapse = " ")
      ret
    }
    
    molas <- "MOLAS"
    input <- c("again,", molas)
    input
    test(input)
    molas
    input
    test()
    test(NULL)
    


[ Go to top ]

Maintained: Wei-Chen Chen
E-Mail: wccsnow @ gmail.com
Last Revised: Dec 12 2016, 09:44 (CST Taipei, Taiwan)
Created: Oct 06 2003
free counters Best Resolution
IE6.0
1280x1024
small font