Displaying 20 results from an estimated 20000 matches similar to: "How to understand packages, namespaces, environments"
2010 Feb 23
3
Best style to organize code, namespaces
Hi all,
I'm hoping someone could tell me what best practices are as far as
keeping programs organized in R. In most languages, I like to keep
things organized by writing small functions. So, suppose I want to
write a function that would require helper functions or would just be
too big to write in one piece. Below are three ways to do this:
################### Style 1 (C-style)
2007 Jun 29
2
DesignPatterns part 2: humane class names with namespaces
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Dear list!
In an effort to get feedback and spread the word, here follows the second
article about possibilities to structure manifests. These Design Patterns are
more general than the typical Puppet Recipie and will receive a own page on
the wiki when I collect enough[1] material.
To the meat: humane class names with namespaces
Class names
2004 Nov 23
3
str() resets class for environments
I noticed the following today --- str() seems to remove any extra
class information added to an environment.
> e <- new.env()
> class(e)
[1] "environment"
> class(e) <- c("foo", class(e))
> class(e)
[1] "foo" "environment"
> str(e)
Classes 'foo', 'environment' length 0 <environment>
> class(e)
[1]
2010 Nov 15
2
Trying to understand the search path and namespaces
Hi all,
I'm trying to understand how the search path and namespaces interact.
For example, take the devtools package which suggests the testthat
package. Here's what the search path looks like after I load each of
those packages:
> library(devtools)
> search()
[1] ".GlobalEnv" "package:devtools" "package:stats"
[4]
2003 Apr 06
0
namespaces and assignment: a problem/question
This is a question about namespaces and assignment. It's occasioned because
one of my functions stopped working at about R1.6 with the arrival of
'namespace:base', and I'm anxious to find out what will happen when 1.7
arrives. But the question might be of more general relevance (hence my
desire to get it in before "lockdown" on 9th April).
I have a function
2004 Jan 27
3
Directory-like data organisation w/ environments?
Dear r-users!
I wonder if there is a way of designing a directory like structure for
holding my data using environments?
It would be nice if I could implement a kind of 'cd' command to change
to a differend environment etc.
Can anybody give me a hint?
-cl
--
Christoph Lange
MPI fuer biologische Kybernetik |Phone: +49-7071-601-607|
Postfach 2169, D-72012 Tuebingen |FAX:
2002 Sep 19
3
savehistory directories and quitting R (PR#2038)
#
# r-bugs@r-project.org
#
######################################################
Because I work in different directories, but always want to save my
.Rhistory in the same place, I have changed the system function savehistory
to this:
function (file = "D:/R50/.Rhistory")
invisible(.Internal(savehistory(file)))
When I use q() to quit R, and it asks me whether I want to
2002 Oct 21
1
savehistory directories and quitting R (PR#2038)
Thanks-- as Duncan Murdoch also noted, R_HISTFILE can be used to solve my
problem, as below. BTW it's not easy to find out about R_HISTFILE in the
help system or manuals, though, unless you already know it exists-- it only
seems to be described under startup options, not things to do with history.
However, Duncan's reply did hint at an inconsistency, in that savehistory()
defaults to
2004 Jun 09
1
Using macros
Dear list members,
I've been puzzling over how best to clean up the code for my Rcmdr package.
In particular, there's a lot of repetitive tcltk code in the package, and as
Martin M?chler has pointed out to me, this makes the package difficult to
maintain.
If R were Lisp, I'd use macros for much of the clean up. My efforts to do
similar things with R functions has run into problems
2001 Mar 30
1
session request to *SMBSERVER failed (Called name not present)
Hi, I am trying to list the shares on a windows ME machine and I am getting
the following
[root]# smbclient -L 192.168.0.253
added interface ip=192.168.0.1 bcast=192.168.0.255 nmask=255.255.255.0
session request to 192.168.0.253 failed (Called name not present)
session request to 192 failed (Called name not present)
session request to *SMBSERVER failed (Called name not present)
I have also tried
2023 Nov 15
1
saveRDS()/readRDS() on environments
Dear r-devel,
I was surprised to see that saveRDS() and readRDS() work quite well with
environments, see below:
```
z <- 3 # in global env
y <- new.env()
y$a <- 1
x <- new.env(parent = y)
x$b <- 2
saveRDS(x, "x.RDS")
# in a new session
x <- readRDS("x.RDS")
y <- parent.env(x)
x$b
#> [1] 2
y$a
#> [1] 1
parent.env(y)
#> <environment:
2016 Dec 12
2
why does parent.frame() cycle when called from inside capture.output()?
Hello R devel/help,
I ran into this strange behavior:
# showstack is supposed to walk through the stack of parent
# environments when it is called:
showstack = function() {
env = environment()
for(i in 1:12) {
env = do.call(parent.frame, list(), env=env)
print(env)
}
}
# a simple chain of functions:
g3=function(t) showstack()
2016 Dec 12
2
why does parent.frame() cycle when called from inside capture.output()?
Hello R devel/help,
I ran into this strange behavior:
# showstack is supposed to walk through the stack of parent
# environments when it is called:
showstack = function() {
env = environment()
for(i in 1:12) {
env = do.call(parent.frame, list(), env=env)
print(env)
}
}
# a simple chain of functions:
g3=function(t) showstack()
2003 Dec 13
1
Mapping CIFS/Samba problem
All,
The Windows 2000 client is on my side of the firewall (the error message is: "remote computer is not available"), the Windows XP client is on the other side of the firewall, (the error message is: "The specified network name is no longer available"). I am able to ping both the IP address and server name of the CIFS/Samba server. I cannot perform the mapping, via Map
2004 Jul 14
2
tracing something in a namespace (PR#7091)
# Your mailer is set to "none" (default on Windows),
# hence we cannot send the bug report directly from R.
# Please copy the bug report (after finishing it) to
# your favorite email program and send it to
#
# r-bugs@r-project.org
#
######################################################
> x <- rnorm(10)
> y <- 1:10
> xyplot(y ~ x)
>
2005 Feb 08
1
Using GRASS/R interface with an xy location
I am using GRASS 5.7 and R 2.0 for OS X. I have a simple xy location I
am doing some theoretical work with and would like to import maps into
R using the interface in order to do analyses. Yet when I attempt to
do this, I get the following error:
>G<-gmeta()
Error in gmeta() : region for current mapset is invalid
line 11: <top: 100>
run "g.region"
I traced the
2009 Nov 02
4
Incremental ReadLines
I've been trying to figure out how to read in a large file for a few days
now, and after extensive research I'm still not sure what to do.
I have a large comma delimited text file that contains 59 fields in each
record.
There is also a header every 121 records
This function works well for smallish records
getcsv=function(fname){
ff=file(description = fname)
x <- readLines(ff)
2019 Oct 09
2
S3 lookup rules changed in R 3.6.1
tl;dr: S3 lookup no longer works in custom non-namespace environments as of
R 3.6.1. Is this a bug?
I am implementing S3 dispatch for generic methods in environments that are
not
packages. I am trying to emulate the R package namespace mechanism by
having a
?namespace? environment that defines generics and methods, but only exposes
the
generics themselves, not the methods.
To make S3 lookup work
2008 Jul 15
1
methods/namespaces/possible bug
Using
> methods("plot")
[1] plot.Date* plot.HoltWinters* plot.POSIXct*
[4] plot.POSIXlt* plot.TukeyHSD plot.acf*
[7] plot.data.frame* plot.decomposed.ts* plot.default
[10] plot.dendrogram* plot.density plot.ecdf
[13] plot.factor* plot.formula* plot.hclust*
[16] plot.histogram* plot.isoreg* plot.lm
[19] plot.medpolish*
2015 Jan 21
2
reducing redundant work in methods package
Hi all,
The function call series genericForPrimitive -> .findBasicFuns -> .findAll
happens 4400 times while the GenomicRanges package is loading. Each time
.findAll follows a chain of environments to determine that the methods
namespace is the only one that holds a variable called .BasicFunsList. This
accounts for ~10% of package loading time. I'm sure there is some history
to that