r - 如何在加载包时完全防止 "The following object is masked from ‘package:...’ :. .."问题/警告?

标签 r function notation

当我加载我创建的包时,我收到以下警告:

"The following object is masked from ‘package:utils’:combn"

即使我在 R 工作目录中“R”文件夹的 .R 文件的函数定义中使用了combinat::combn。

有没有办法消除“...对象被...屏蔽”警告? (我根本不想屏蔽 Comn;请参阅下面 Gregor 的帖子。)

我在包中的函数定义中添加了“combinat::”前缀,只要我想使用combinat的组合,以免收到上述警告(combinat::combn与utils::combn的混合)。

gctemplate 是 causfinder 包的一个函数(对于那些想要掌握该函数的人,我删除了“combinat::”;当我在function gctemplate,我仍然收到上述警告):

#' gctemplate
#'
#' Granger causality template for a given system in the desired pattern.
#'
#' Assume a system in which its Granger causality relations among its variables will be searched is given. For the variables of this system (with nvars variables), some varibles may cause (causers, like independents) some others (those that are caused by causers, like dependents) conditional on some others in the system. The function gctemplate has three arguements to list all the possible causation pattern in which Granger causality will be searched. As is known, dependent and independent variables are not specified in the beginning of a Granger analysis, the analysis reveals them.
#'
#' @param nvars integer. The number of all the variables in a given system.
#' @param ncausers integer. The selected number of causer (independent-like) variables
#' @param ndependents integer. The selected number of variables that are caused by the causers, number of dependent-like variables
#' @return granger causality template
#' @author Erdogan Cevher erdogancevher@@gmail.com
#' @seealso \code{\link{conditionalGb}}
#' @examples
#' ## List all G-causalities in a VAR system of 5 variables that will be searched in the pattern of 1 
#' ## causer (like-independent) variable and 2 like-dependents conditional on 5-(1+2)=2 of the remaining 
#' ## variable(s) in the system. Varibles are assigned to numbers 1 to nvars. 
#' ## "1 2 5 3 4" in the rsulting line of gctemplate is to indicate the 
#' ## (conditonal, partial, etc.) G-causality from variable 1 to varibles 2 and 5 
#' ## conditonal on variables 3 and 4.
#' # gctemplate(5,1,2)
#' ## The number of all G-causalities to be searched in the above pattern.
#' #dim(gctemplate(5,1,2))[[1]]
#' @importFrom combinat combn
#' @export
gctemplate <- function(nvars, ncausers, ndependents){  
independents <- combn(nvars, ncausers)  
patinajnumber <-  dim(combn(nvars - ncausers, ndependents))[[2]]  
independentspatinajednumber <- dim(combn(nvars, ncausers))[[2]]*patinajnumber   
dependents <- matrix(, nrow = dim(combn(nvars, ncausers))[[2]]*patinajnumber, ncol = ndependents)  
for (i in as.integer(1:dim(combn(nvars, ncausers))[[2]])){     
dependents[(patinajnumber*(i-1)+1):(patinajnumber*i),] <- t(combn(setdiff(seq(1:nvars), independents[,i]), ndependents))  
}  
independentspatinajed <- matrix(, nrow = dim(combn(nvars, ncausers))[[2]]*patinajnumber, ncol = ncausers)  
for (i in as.integer(1:dim(combn(nvars, ncausers))[[2]])){     
for (j in as.integer(1:patinajnumber)){     
independentspatinajed[(i-1)*patinajnumber+j,] <- independents[,i]    
}}  
independentsdependents <- cbind(independentspatinajed, dependents)  
others <- matrix(, nrow = dim(combn(nvars, ncausers))[[2]]*patinajnumber, ncol = nvars - ncausers - ndependents)   
for (i in as.integer(1:((dim(combn(nvars, ncausers))[[2]])*patinajnumber))){    
others[i, ]  <- setdiff(seq(1:nvars), independentsdependents[i,])   
}  
causalitiestemplate <- cbind(independentsdependents, others)  
causalitiestemplate  
}  

以下是DESCRIPTION文件的内容:

Package: causfinder  
Type: Package  
Title: A visual analyser for pairwise and multivariate conditional and partial  
Granger causalities. For a list of documented functions, use library(help =  
"causfinder")  
Version: 2.0  
Date: 2014-10-05  
Author: Erdogan CEVHER <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9df8eff9f2fafcf3fef8ebf5f8efddfaf0fcf4f1b3fef2f0" rel="noreferrer noopener nofollow">[email protected]</a>>  
Maintainer: Erdogan CEVHER <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="197c6b7d767e78777a7c6f717c6b597e74787075377a7674" rel="noreferrer noopener nofollow">[email protected]</a>>  
Description: Given a system of finite number of variables with their data in a  
matrix, the functions in the causfinder package analyze the pairwise and  
multivariate conditional and partial Granger causalities in a systematic  
and overall approach. By "overall approach" we mean that all the  
G-causalities among the variables in a certain desired pattern are  
calculated (the user then can retrieve his/her G-causality in interest as  
one element of the pattern). This pattern may correspond to pairwise or  
multivariate Granger causalities. Some of the functions in the package use  
bootstrapping whereas some others not. The analysis of the Granger  
causalities are performed via various ways; i.e., presenting the F  
statistics, p values, lower bounds and upper bounds of the bootstrapping  
values etc., and via presenting various plots and grid matrixes. For a list  
of documented functions, use library(help = "causfinder")  
Depends:  
    R (>= 3.0.2)  
Imports:  
    np(>= 0.50-1),RColorBrewer(>= 1.0-5),grid,scales(>= 0.2.4),boot(>= 1.3-11),calibrate(>= 1.7.2),combinat(>= 0.0-8),corpcor(>= 1.6.6)  
License: GPL (>= 3)  
LazyLoad: yes  
LazyData: yes  
URL: https://github.com/erdogancevher/causfinder  

注意:将combinat包的函数combn重命名为combnnn并将其内容(其.R文件等)放入我的包R文件夹中;并且应用 rexoginzation 程序可能不会导致上述警告。我试图获得的只是一种防止警告的系统方法,而不是我在本说明中描述的非常棘手/漫长的方法。

最佳答案

如果路径上部的对象(遮蔽你真正想要的对象的对象)是你可以不需要的东西,你可以使用命令

rm(对象名称)

做的时候:

要求(ISLR)

我收到消息:

以下对象被_by_‘.GlobalEnv’屏蔽

所以它是通过这样做修复的

rm(自动)

现在我从 ISLR 包中引用 Auto,而不是 GlobalEnv

关于r - 如何在加载包时完全防止 "The following object is masked from ‘package:...’ :. .."问题/警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27640893/

相关文章:

r - 如何在R中使用窗口函数

r - 快速分组简单线性回归

c - 如何将字符串转换为 double 浮点值?

javascript - Sciter 速记符号

algorithm - 计算大 O 符号

r - WCAG 2.1 与 Shiny 仪表板应用程序表单标签的兼容性

r - Shiny (R) 中的自引用 react 变量

c - C 函数调用的返回值?

javascript - JavaScript 中的函数调用

C# 符号理解 Select(int.Parse)