2017-05-25 51 views
0

背景

我有一個簡單的函數叫TBT。這個函數有一個叫做x的參數。用戶可以提供任何類型rdistribution_name()(例如,rnorm()rf()rt()rbinom()等)中的R爲現有參數x除了一個:rcauchy()」。R可以識別用作函數參數的分佈類型嗎?

問題

我想知道如何能[R認識到,用戶提供了一個rcauchy()作爲輸入x,當是這種情況,那麼R發出警告消息?

這裏是我的R代碼裏面沒有成功:

TBT = function(x) { 

if(x == rcauchy(...)) { warning("\n\tThis type of distribution is not supported.") } 

} 

TBT(x = rcauchy(1e4)) 

Error in TBT(rcauchy(10000)) : '...' used in an incorrect context

+0

來到你嘗試:'gauchy.test()':https://www.rdocumentation.org/packages/goft/versions/ 1.3.1/topics/cauchy.test? – BigDataScientist

回答

1

如果您expeciting他們時,他們打電話給你的功能就調用隨機函數,你可以這樣

TBT <- function(x) { 
    xcall <- match.call()$x 
    if (class(xcall)=="call" && xcall[[1]]=="rcauchy") { 
     warning("\n\tThis type of distribution is not supported.") 
    } 
} 
TBT(x = rcauchy(1e4)) 

但這不會像

x <- rcauchy(1e4) 
TBT(x) 

R可以不跟蹤,其中在x變量中的數據從

相關問題