2 回答

TA貢獻1842條經(jīng)驗 獲得超13個贊
library和require都可以載入包,但二者存在區(qū)別。
在一個函數(shù)中,如果一個包不存在,執(zhí)行到library將會停止執(zhí)行,require則會繼續(xù)執(zhí)行。
require將會根據(jù)包的存在與否返回true或者false,
t <- library("abc")
Error in library("abc") : there is no package called 'abc'
> test#library沒有返回值
Error: object 'test' not found
> test <- require("abc")
Loading required package: abc
Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
there is no package called 'abc'
> test#require有返回值
[1] FALSE
利用上面這一點可以進行一些操作
if(require("lme4")){
print("lme4 is loaded correctly")
} else {
print("trying to install lme4")
install.packages("lme4")
if(require(lme4)){
print("lme4 installed and loaded")
} else {
stop("could not install lme4")
}
}

TA貢獻1812條經(jīng)驗 獲得超5個贊
//不斷創(chuàng)建線程,直到再不能創(chuàng)建為止
m_nCount=nCount;
UpdateData(FALSE);
Sleep(5000);
//延時5秒,等待所有創(chuàng)建的線程結(jié)束
GetDlgItem(IDC_TEST)->EnableWindow(TRUE);
m_bRunFlag=TRUE;
}
- 2 回答
- 0 關(guān)注
- 790 瀏覽
添加回答
舉報