Send a text string containing double quotes to function

前端 未结 2 1257
遇见更好的自我
遇见更好的自我 2020-12-10 08:05

I\'m having a problem with using double quotes while formatting text strings being sent to functions in R.

Consider an example function code:

foo <         


        
2条回答
  •  隐瞒了意图╮
    2020-12-10 08:59

    You can try these approaches:

    foo <- function(numarg = 5, textarg = "** Default text **" ){ 
        cat(c(textarg, "\n")) 
        val <- (numarg^2) + numarg
        return(val) 
    }
    
    foo <- function(numarg = 5, textarg = "** Default text **" ){ 
        print(noquote(textarg)) 
        val <- (numarg^2) + numarg
        return(val) 
    }
    
    foo( 4, "Learning R is fun!" )
    foo( 4, 'Learning "R" is fun!' )
    

提交回复
热议问题