我對R不太熟悉,但無論如何我正在爲C庫編寫一個R包裝器。我遇到了這個問題。我如何確定輸入參數是否是字符串?詳細地說,我應該寫這樣的:R中的字符串和字符有什麼區別?
dyn.load("hello.so")
do_process <- function(str) {
if(!is.character(str))
stop("not a character or string");
result <- .Call("hello", as.character(str))
return result
}
或本:
dyn.load("hello.so")
do_process <- function(str) {
if(!is.string(str))
stop("not a character or string");
result <- .Call("hello", as.string(str))
return result
}
感謝。
在鹼'R'沒有功能'is.string'也不存在數據類型'string'。他們是'as'character'和'character'。另外,避免使用重要的基本函數作爲變量名稱。具體來說'str'用於查看對象的結構。 – Justin
@Justin我不知道,但我已閱讀'is.string'的用法:http://rss.acs.unt.edu/Rdoc/library/xtable/html/string.html,並感謝您的建議'str'用法。 – lulyon
@Justin我的錯。謝謝你指出這個錯誤。 – lulyon