2

When I load a package I created, I get the following warning:

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

even though I used combinat::combn in function definitions in .R files of "R" folder in R's working directory.

Isn't there any way to get rid of "...object is masked from..." warning? (I don't want to mask combn at all; See Gregor's post below.)

I added "combinat::" prefix in my definitions of functions in my package wherever I wanna use the combn of combinat in order not to get the above warning (mixing of combinat::combn with utils::combn).

gctemplate is a function of the package causfinder (I removed "combinat::" for those who want to grasp the function; when I pump "combinat::" prefix wherever I see combn in the function gctemplate, I still received the above warning):

#' 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  
}  

The following is the content of DESCRIPTION FILE:

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 <erdogancevher@gmail.com>  
Maintainer: Erdogan CEVHER <erdogancevher@gmail.com>  
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  

NOTE: Renaming the function combn of the combinat package as combnnn and putting its content (its .R file etc.) to my package R folder; and applying rexoginzation procedure may not result in the above warning. What I tried to obtain is just a systematic way to prevent the warning, not the very tricky/long way I described in this note.

Erdogan CEVHER
  • 1,788
  • 1
  • 21
  • 40
  • 3
    You could rename your own function something else or not export it from your package. If you load a package that exports a function name identical to an already loaded package, you will get that error (and `utils` is a default package). – MrFlick Dec 24 '14 at 18:28
  • 3
    I would vote for not using `combn` unless you have crafted a function that merely extends the functionality and calling syntax of `utils::combn`. That is a fairly basic function that shouldn't be mucked with unless you are just adding named arguments on the right side of the dots. (But it's not an error, only a warning.) – IRTFM Dec 24 '14 at 18:32
  • My package name: causfinder, the function that uses conbinat::combn is gctemplate. That is, I know utils is a default package, and I did not define any function with the name "combn" in my package. I got the warning under these conditions. – Erdogan CEVHER Dec 24 '14 at 18:35
  • 2
    Perhaps this question-answer can help: [Disable messages upon loading package in R](https://stackoverflow.com/questions/8681688/disable-messages-upon-loading-package-in-r) – zhaoy Dec 24 '14 at 18:44
  • @zhaoy, I'll analyze Dirk Eddelbuettel's way (R> suppressMessages(library(causfinder)) to solve if it prevents only warnings, but not errors. – Erdogan CEVHER Dec 24 '14 at 18:52
  • 1
    I suspect you're calling another package that has a function that is named that and you're importing the whole package. In which case you only want to import the functions you want. – Tyler Rinker Dec 24 '14 at 20:03
  • 2
    You should edit your question to make it clear if (a) you don't mind masking `combn`, you just don't want to see the warning about it, or (b) you don't want to mask `combn` at all and are having trouble with that. – Gregor Thomas Dec 24 '14 at 20:06
  • @Gregor, U are right. My question is "(b)" in your post. I consider now how to reflect that to the question. You may offer the change as well. I tried adding "combinat::" prefix to get rid of the trouble totally. Unfortunately, it did not solve. – Erdogan CEVHER Dec 24 '14 at 22:33
  • @Tyler Rinker, My namespace file (Auto-Generated by roxygen2 (4.1.0)) has "importFrom(combinat,combn)" line in it. Yes, I wanted to use only a few functions from combinat package. – Erdogan CEVHER Dec 24 '14 at 22:45
  • @GSee, I just copy-paste the body of the function (those with non-roxygen2 markup) and it gave the result. > gctemplate(5,1,2) [,1] [,2] [,3] [,4] [,5] [1,] 1 2 3 4 5 [2,] 1 2 4 3 5 ............................. [30,] 5 3 4 1 2. I wonder what error did you get? What do you mean: Did gctemplate give error OR didn't you get "object is masked from" warning? – Erdogan CEVHER Dec 25 '14 at 19:19
  • I got no error and no warning. That's my point. When I build a package created using the the info you've provided, I can load it without getting a warning about `combn` being masked. – GSee Dec 25 '14 at 19:22
  • Does your package pass `R CMD check` without any warnings or notes? There could be a stray `library` call somewhere. If you put the code in that github repository we could take a look. – GSee Dec 25 '14 at 19:23
  • @GSee, Yes, I have no problem in that; it passed the checking in both ways: A. "Windows command line": 1. Start – cmd - Enter. Then, R's working directory cd C:\Users\erdogan\Documents\Revolution 2. CRAN check: R CMD check causfinder B. "From Revolution R Ent Console": devtools::check("C:/Users/erdogan/Documents/Revolution/causfinder"). I just wanted to learn an overall fix the issue. The "object is masked" warning does not prevent the package from being properly checked. – Erdogan CEVHER Dec 25 '14 at 19:34
  • 1
    If the package isn't being attached, and all you're doing is importing that function into your package's NAMESPACE and you are not exporting it, then you shouldn't get that warning. I tried it by creating a package called "test" that uses your DESCRIPTION and your function and didn't get the warning when I call `library(test)`. If I call `library(combinat)`, I do get the warning. – GSee Dec 25 '14 at 19:45

1 Answers1

3

If the object in the superior part of the path (the object shadowing the object you really want) is something you can do without, you can use the command

rm(object_name)

When doing:

require(ISLR)

I get the message:

The following object is masked _by_ ‘.GlobalEnv’

So it is fixed by doing

rm(Auto)

And I now reference Auto from the ISLR package rather than GlobalEnv

Noel Evans
  • 8,113
  • 8
  • 48
  • 58