function call overhead
Hi Paul,
`:::`
function (pkg, name)
{
pkg <- as.character(substitute(pkg))
name <- as.character(substitute(name))
get(name, envir = asNamespace(pkg), inherits = FALSE)
}
<environment: namespace:base>
and
`::`
function (pkg, name)
{
pkg <- as.character(substitute(pkg))
name <- as.character(substitute(name))
ns <- tryCatch(asNamespace(pkg), hasNoNamespaceError = function(e) NULL)
if (is.null(ns)) {
pos <- match(paste("package", pkg, sep = ":"), search(),
0L)
if (pos == 0)
stop(gettextf("package %s has no name space and is not on
the search path"),
sQuote(pkg), domain = NA)
get(name, pos = pos, inherits = FALSE)
}
else getExportedValue(pkg, name)
}
<environment: namespace:base>
are the reasons I think.
Jeff
On Wed, Feb 16, 2011 at 12:13 PM, Paul Gilbert
<pgilbert at bank-banque-canada.ca> wrote:
(subject changed from: RE: [Rd] Avoiding name clashes: opinion on best practice naming ?conventions) Dominick Is this really true? Is there a speed advantage to defining a local function this way, say, within another function, and then calling it within a loop rather than the original? Do you have data on this? Paul
-----Original Message----- From: r-devel-bounces at r-project.org [mailto:r-devel-bounces at r- project.org] On Behalf Of Dominick Samperi Sent: February 16, 2011 12:44 PM
...
Since the resolution of myPkg::foo() occurs at runtime (via a function call) instead of at compile time (as it would in C++), this practice can introduce a significant performance hit. This can be avoided by doing something like: mylocalfunc <- myPkg::foo [tight loop that uses mylocalfunc repeatedly] Here mylocalfunc would not be exported, of course. Dominick
... ==================================================================================== La version fran?aise suit le texte anglais. ------------------------------------------------------------------------------------ This email may contain privileged and/or confidential information, and the Bank of Canada does not waive any related rights. Any distribution, use, or copying of this email or the information it contains by other than the intended recipient is unauthorized. If you received this email in error please delete it immediately from your system and notify the sender promptly by email that you have done so. ------------------------------------------------------------------------------------ Le pr?sent courriel peut contenir de l'information privil?gi?e ou confidentielle. La Banque du Canada ne renonce pas aux droits qui s'y rapportent. Toute diffusion, utilisation ou copie de ce courriel ou des renseignements qu'il contient par une personne autre que le ou les destinataires d?sign?s est interdite. Si vous recevez ce courriel par erreur, veuillez le supprimer imm?diatement et envoyer sans d?lai ? l'exp?diteur un message ?lectronique pour l'aviser que vous avez ?limin? de votre ordinateur toute copie du courriel re?u.
______________________________________________ R-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Jeffrey Ryan jeffrey.ryan at lemnica.com www.lemnica.com