2 回答

TA貢獻(xiàn)1842條經(jīng)驗(yàn) 獲得超13個(gè)贊
library和require都可以載入包,但二者存在區(qū)別。
在一個(gè)函數(shù)中,如果一個(gè)包不存在,執(zhí)行到library將會(huì)停止執(zhí)行,require則會(huì)繼續(xù)執(zhí)行。
require將會(huì)根據(jù)包的存在與否返回true或者false,
t <- library("abc")
Error in library("abc") : there is no package called 'abc'
> test#library沒(méi)有返回值
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
利用上面這一點(diǎn)可以進(jìn)行一些操作
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貢獻(xiàn)1812條經(jīng)驗(yàn) 獲得超5個(gè)贊
//不斷創(chuàng)建線程,直到再不能創(chuàng)建為止
m_nCount=nCount;
UpdateData(FALSE);
Sleep(5000);
//延時(shí)5秒,等待所有創(chuàng)建的線程結(jié)束
GetDlgItem(IDC_TEST)->EnableWindow(TRUE);
m_bRunFlag=TRUE;
}
- 2 回答
- 0 關(guān)注
- 800 瀏覽
添加回答
舉報(bào)