Re: [R] Testing memory limits in R??

2009-07-06 Thread Andy Zhu
check Memory in R:

?Memory



--- On Mon, 7/6/09, Scott Zentz  wrote:

From: Scott Zentz 
Subject: [R] Testing memory limits in R??
To: r-help@r-project.org
Date: Monday, July 6, 2009, 3:52 PM

Hello Everyone,

   We have recently purchased a server which has 64GB of memory running a 64bit 
OS and I have compiled R from source with the following config

./configure --prefix=/usr/local/R-2.9.1 --enable-Rshlib --enable-BLAS-shlib 
--enable-shared --with-readline --with-iconv --with-x --with-tcktk --with-aqua 
--with-libpng --with-jpeglib

and I would like to verify that I can use 55GB-60GB of the 64GB of memory 
within R. Does anyone know how this is possible? Will R be able to access that 
amount of memory from a single process? I am not an R user myself but I just 
wanted to test this before I turned the server over to the researchers..

Thanks!
-scz

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



  
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] #INCLUDE

2009-07-08 Thread Andy Zhu
source(_external_file_name)

--- On Wed, 7/8/09, Idgarad  wrote:

From: Idgarad 
Subject: [R] #INCLUDE
To: r-help@r-project.org
Date: Wednesday, July 8, 2009, 11:16 AM

What is R's equivalent to a C-like #include to incorporate external files. I
have a 2k line function that is generated and need to include it at runtime
but not manage it as a package (as it changes hourly.) Any ideas?

    [[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



  
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] cannot allocate a vector with 1920165909 length

2009-07-28 Thread Andy Zhu
Out of memory? How large is your physical memory?

--- On Tue, 7/28/09, zhijie zhang  wrote:

From: zhijie zhang 
Subject: [R] cannot allocate a vector with 1920165909 length
To: r-h...@stat.math.ethz.ch
Date: Tuesday, July 28, 2009, 9:49 PM

Dear Rusers,
 The error for the  following was that it cannot allocate the vector of
length 1920165909.
a <- expand.grid(se1=0:100/100, sp1=0:100/100, se2=0:100/100, sp2=0:100/100,
DR=0:100/100)
 How to solve it? Maybe setwd(dir) can, i am not very sure about it.
 Any ideas about it?

    [[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



  
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] R CMD build/install: wrong Rtools include path is passed to g++

2010-12-21 Thread Andy Zhu
Hi:

I am trying to build/install rparallel source package in win32 using Rtools/R 
CMD.  However, R CMD build or install fails.  The R CMD build output shows that 
the path of Rtools/MinGW/include is wrong in g++ -I. How can I pass/configure 
the correct include path to R CMD? Tried this in both R 2.12 and 2.11 with 
compatible Rtools and Miktex/chm helper. Neither succeeded.

Note, the R/Rtools/MinGW setting works fine if the package doesn't have C/C++ 
code.  I was able to install my own R package which doesn't have C/C++ code.


  
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R CMD build/install: wrong Rtools include path is passed to g++

2010-12-21 Thread Andy Zhu
Never mind.  Found the solution: the package coded the rtools path in 
Makevars.win.  So I was able to compile (but have another problem though).  But 
not sure if there is an environment name for rtools, maybe RTOOLS_HOME ...

Thanks.



- Forwarded Message 
From: Andy Zhu 
Cc: r-help@r-project.org
Sent: Mon, December 20, 2010 11:33:31 PM
Subject: [R] R CMD build/install: wrong Rtools include path is passed to g++


Hi:

I am trying to build/install rparallel source package in win32 using Rtools/R 
CMD.  However, R CMD build or install fails.  The R CMD build output shows that 
the path of Rtools/MinGW/include is wrong in g++ -I. How can I pass/configure 
the correct include path to R CMD? Tried this in both R 2.12 and 2.11 with 
compatible Rtools and Miktex/chm helper. Neither succeeded.

Note, the R/Rtools/MinGW setting works fine if the package doesn't have C/C++ 
code.  I was able to install my own R package which doesn't have C/C++ code.


  
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] installation of R/parallel package in win32/64

2010-12-21 Thread Andy Zhu
This is to summarize my workaround to install R/parallel in win32/64 boxes.  
Recently I had problems to install rparallel:
1. The package's Makevars.win coded include fixed path for Rtools
2. package is written in C++; Rtools and R are not intended to run g++ by 
default.

My workaround:
1. Need to install R, Rtools as usual.  Note Rtools 2.12 has both 32bit mingw 
and 64 bit.  However, it doesn't include package for g++ and libstdc++.  You 
need to install these 2 packages into rtools from sourceforge first.
2. In rparallel source tree, open Makevars.win: change the PKG_CPPFLAGS and 
PKG_LIBS variables to point to your correct rtools and rtools/mingw directories.
3. In R_installation/etc: open i386 or win64 (forget the name for 64bit) and 
open Makeconf file; look for DLLFLAGS += ... and append -static-libstdc++.  
This 
flag will cause g++ to statically link in libstdc++.

then you can run usual R CMD INSTALL rparallel.

Good luck.


  
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] getting time series into r

2011-05-23 Thread Andy Zhu
No attachment.  But if your date is in the MMDD then the format syntax is 
...format="%Y%m%d").

Best,

--- On Mon, 5/23/11, Heiman, Thomas J.  wrote:

From: Heiman, Thomas J. 
Subject: [R] getting time series into r
To: "R-help@r-project.org" 
Date: Monday, May 23, 2011, 2:32 PM


Hi,

I am trying to get the attached following two timeseries (these are small 
subsets of the whole thing) into R so I can merge them using zoo.

tmp <- read.table("baltimore.csv", sep = ",") ##This is timeseries 2
z <- zoo(tmp[, 2:20], as.Date(as.character(tmp[, 1]), format = "%y %m %d"))

tmp1 <- read.table("baltimorefludata.csv", sep = ",") ##This is timeseries 1
z2 <- zoo(tmp[,2], as.Date(tmp[, 1]), format = "%m %d %y"))

R is not recognizing Date or YEARMODA as dates..Any suggestions on what I am 
doing wrong or how to fix it would be greatly appreciated!!!

Sincerely,

tom








Thomas Heiman, PhD
Info Systems Eng, Sr
The MITRE Corporation | Center for Enterprise Modernization
Office: 703-983-2951 | thei...@mitre.org

    [[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

-Inline Attachment Follows-

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] writing dates to a file

2011-05-24 Thread Andy Zhu
I think if you attach the output file would make clear.  I guess it is very 
likely your merge has the problem, not the write.table.  You may need "by" 
parameter in merge based on the date.  It also could be date value is converged 
to numeric value, in this case you just need to convert it back.


--- On Tue, 5/24/11, Heiman, Thomas J.  wrote:

From: Heiman, Thomas J. 
Subject: [R] writing dates to a file
To: "R-help@r-project.org" 
Date: Tuesday, May 24, 2011, 2:34 PM

Hi,

I have attached the data files to this note.   I use this code:

library(zoo)
z1 <- read.zoo("baltimorefludata.txt", format = "%m/%d/%Y", header = TRUE)
z2 <- read.zoo("baltimorew.txt", format = "%Y%m%d", header = TRUE)

z3<-merge(z1,z2)

write.table(z3, "fluweatherdata_baltimore2.txt", sep="\t")

R is writing the other data to the file but not the dates...  Is there a way to 
also write the dates to the file?  Thank you!!

Sincerely,

tom

Thomas Heiman, PhD
Info Systems Eng, Sr
The MITRE Corporation | Center for Enterprise Modernization
Office: 703-983-2951 | thei...@mitre.org

-Inline Attachment Follows-

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] matrix not working

2011-05-26 Thread Andy Zhu
Dat:

1. you can use as.matrix to convert data.frame to matrix;
2. it is likely that the internal representation of your data.frame may not be 
numerical value; matrix can only take on numeric.



--- On Thu, 5/26/11, Dat Mai  wrote:

From: Dat Mai 
Subject: [R]  matrix not working
To: r-help@r-project.org
Date: Thursday, May 26, 2011, 12:24 PM

Hello All,

I'm trying to create a matrix from a dataframe (let's call it df):
..a..b.c.d
a   inputs      output
b   inputs      output
c   inputs      output
d   inputs      output
e   inputs      output

The inputs are represented by columns a and b
The outputs are represented by columns c and d, but the only outputs are
those from column d
- some values from column d are NA
- column d was created with the code:

df$d=rank(df$c, na.last="keep")

#--R Code-#
item=unique(df$a)
n=length(list)

r=matrix(data=NA,nrow=n, ncol=n, dimnames=list(PRR1=item, PRR2=item))

for(j in 2:ln)
{
  for(i in 1:(j-1))
  {
    input1=rownames(r)[i]
    input2=colnames(r)[j]

    q=df[(df$a==input1 & df$b==input2), "d"]

    if(length(q)==0)
    {
      q=df[(df$a==input2 & df$b==input1), "d"]
    }

    if(length(q)==0)
    {
      q=NA
    }

    r[j,i]=q
    r[i,j]=q
    r[j,j]=q
  }
}

The result is a matrix with the appropriate dimensions, but everything is
filled with NA instead of the rankings of the various combinations. I'd like
for the matrix to be filled with the ranking values--what have I done wrong?
-- 
Best,
Dat Mai
PhD Rotation Student
Albert Einstein College of Medicine

    [[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Run R script automatically each morning and email results?

2011-06-01 Thread Andy Zhu
Use cron job scheduler to start r session on your script.

Andy




From: Sarah Henderson 
To: R List 
Sent: Wednesday, June 1, 2011 7:50 PM
Subject: [R] Run R script automatically each morning and email results?

Greetings to all --

I am hoping that someone can offer some insight into an area where I have
very little experience.  I have written some R code that generates a 90-day
plot of temperature vs. mortality.  On whatever day the code is run it will
grab up-to-date vital statistics data from our server and combine it with
up-to-date temperature data from the web.  This is a baby step in automated
surveillance of the relationship between temperature and mortality in our
area.

The next step is to have this code run automatically every morning at
8:00am, and to email the resulting plot to a few key stakeholders.  Can
anyone recommend how I might accomplish this?  Either in R, or some other
user-friendlish solution?

Many thanks,

Sarah

    [[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] R CMD in 2.11.1 error

2010-06-06 Thread Andy Zhu
Hi, 

I have a set of user defined package which I have installed in 2.8.1 for quite 
some time.  I installed 2.11.0 and 2.11.1 a couple of days ago while still 
having 2.8.1 version in my system. For the package, package.skeleton works fine 
in R 2.11.  However, it comes problem when I run Rcmd check/intall. The  
intall.out shows below.

I further tested that I reran R-2.8.1/bin/R CMD check in 2.8.1.  it still 
works.  Then I ran and test the doomed function, gzWrite, in R-2.11.1/binRgui, 
it also works fine.  So, is this the problem in R-2.11.1/bin/Rcmd itself? How 
do I fix it?  I have MinGW, Perl, etc. installed in my system.

I also attached my function gzWrite below.

Thank you very much.


00check.out:

* install options are ' --no-html'

* installing *source* package 'quantplus' ...
** R
** preparing package for lazy loading
** help
Warning: newline within quoted string at gzWrite.Rd:92
Warning: ./man/gzWrite.Rd:99: unknown macro '\n'
Warning: newline within quoted string at gzWrite.Rd:92
Error in parse_Rd("./man/gzWrite.Rd", encoding = "unknown", ...) : 
  Unexpected end of input (in " quoted string opened at gzWrite.Rd:99:46)
ERROR: installing Rd objects failed for package 'quantplus'
* removing 
'd:/developer/projects/quant+/package_builder/quantplus.Rcheck/quantplus'

the problem function:
**
gzWrite = 
# write out a data frame into a gzip file in the format of write.table
function(ds, outdir, outpfx, datepfx, sep='\t', quote=TRUE, row.names=FALSE, 
col.names=TRUE, na='NA', append=FALSE) {
if (F) {
ds = ds.price;
outdir = pathPrice;
outpfx = paste(pfx.price,'_',sep='');
datepfx = fdate;
sep = '\t';
quote = TRUE;
row.names = FALSE;
col.names = TRUE;
na = 'NULL';
append = FALSE;
}
file.out = paste(outdir, '\\', outpfx, datepfx, '.gz', sep='');
file.tmp = paste(outdir, '\\', outpfx, datepfx, '.txt',sep='');
write.table(ds, file=file.tmp, sep=sep, quote=quote, row.names=row.names, 
col.names=col.names, na=na, append=append);
zz = gzfile(file.out, 'w');
raw = file(file.tmp, 'r');
cat(readLines(raw), file=zz, append=F, sep='\n');
close(zz);
close(raw);
unlink(file.tmp);

invisible(NA);
}


  
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] help: error handling in try

2008-09-09 Thread Andy Zhu
First time to post and searched archive for this problem with no clue. My 
version is 2.5.1.

Below is a function to check if a given date is a valid date to a given date 
function object. It uses try (also tried tryCatch but with same problem). When 
given an invalid date, I am hoping try will generate en error message which 
would be picked up by the geterrmessage and thus expecting a false result. but 
this is not the case when it is inside a function. However, if simply run the 
body of function, the ret is indeed a false value. Why are they different?

Many thanks


is.Date=
# adate: a scalar value
# fun: the date function object
# format: the designated date format to date function
function(adate,fun,format) {
    ret=NA;
    error.old=geterrmessage();
    .Internal(seterrmessage('no error'));
    try(fun(adate,format),silent=T);
    error=geterrmessage();
    if (error=='no error') {
    ret=T;
    } else {
    ret=F;
    }
    .Internal(seterrmessage(error.old));
    return(ret);
}

adate='12/2000';
fun=as.Date;
format='%b %Y';

is.Date(adate,fun,format) # returns true which is not correct. 

    ret=NA;

    error.old=geterrmessage();

    .Internal(seterrmessage('no error'));

    try(fun(adate,format),silent=T);

    error=geterrmessage();

    if (error=='no error') {

    ret=T;

    } else {

    ret=F;

    }

    .Internal(seterrmessage(error.old));


ret # shows false which is correct



  
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] help: error handling in try

2008-09-10 Thread Andy Zhu
Thanks, Jim:

One of the purpose of this function is to try not to stop the program and 
generate T/F result for further process. Actually find fix by myself with 
tryCatch (but don't know why try doesn't work). The modified function handles 
potential Date and yearmon in Zoo classes.

is.Date=
# adate: a scalar value
# fun: the date function object
# format: the designated date format to date function
function(adate,fun,format) {
    ret=NA;
    error.old=geterrmessage();
    .Internal(seterrmessage('no error'));
    temp=tryCatch(fun(adate,format),
            error=function(e) {
                .Internal(seterrmessage('error'))
            }
            );
    error=geterrmessage();
    if (error=='error') {
            ret=F;
    } else {
            if (is.na(temp)) {
                ret=F;
            } else {
                ret=T;
            }
    }
    .Internal(seterrmessage(error.old));
    return(ret);
}

adate='12/2000';
fun=as.Date;
format='%b %Y';

is.Date(adate,fun,format); # false

library(zoo);
fun=as.yearmon;
format='%m/%Y';

is.Date(adate,fun,format); # true

Cheer.

--- On Wed, 9/10/08, jim holtman <[EMAIL PROTECTED]> wrote:
From: jim holtman <[EMAIL PROTECTED]>
Subject: Re: [R] help: error handling in try
To: [EMAIL PROTECTED]
Cc: r-help@r-project.org
Date: Wednesday, September 10, 2008, 8:11 AM

Why don't you use 'try' in this fashion:

> f.error <- function(x) if (x == 1) stop('error')
>
> value <- try(f.error(1))
Error in f.error(1) : error
> if (inherits(value, 'try-error')) cat("Got this error:",
value) else print ("no error")
Got this error: Error in f.error(1) : error
> value <- try(f.error(0))  # no error
> if (inherits(value, 'try-error')) cat ("Got this
error:", value) else print("no error")
[1] "no error"
>
>


On Tue, Sep 9, 2008 at 8:56 PM, Andy Zhu <[EMAIL PROTECTED]> wrote:
> First time to post and searched archive for this problem with no clue. My
version is 2.5.1.
>
> Below is a function to check if a given date is a valid date to a given
date function object. It uses try (also tried tryCatch but with same problem).
When given an invalid date, I am hoping try will generate en error message which
would be picked up by the geterrmessage and thus expecting a false result. but
this is not the case when it is inside a function. However, if simply run the
body of function, the ret is indeed a false value. Why are they different?
>
> Many thanks
>
>
> is.Date=
> # adate: a scalar value
> # fun: the date function object
> # format: the designated date format to date function
> function(adate,fun,format) {
> ret=NA;
> error.old=geterrmessage();
> .Internal(seterrmessage('no error'));
> try(fun(adate,format),silent=T);
> error=geterrmessage();
> if (error=='no error') {
> ret=T;
> } else {
> ret=F;
> }
> .Internal(seterrmessage(error.old));
> return(ret);
> }
>
> adate='12/2000';
> fun=as.Date;
> format='%b %Y';
>
> is.Date(adate,fun,format) # returns true which is not correct.
>
> ret=NA;
>
> error.old=geterrmessage();
>
> .Internal(seterrmessage('no error'));
>
> try(fun(adate,format),silent=T);
>
> error=geterrmessage();
>
> if (error=='no error') {
>
> ret=T;
>
> } else {
>
> ret=F;
>
> }
>
> .Internal(seterrmessage(error.old));
>
>
> ret # shows false which is correct
>
>
>
>
>[[alternative HTML version deleted]]
>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?



  
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Woring message in as.yearmon()

2008-09-10 Thread Andy Zhu
Try this modification:
as.yearmon(paste(res[,1], res[,2], sep="-"),format="%Y-%m")Andy

--- On Wed, 9/10/08, Megh Dal <[EMAIL PROTECTED]> wrote:
From: Megh Dal <[EMAIL PROTECTED]>
Subject: [R] Woring message in as.yearmon()
To: [EMAIL PROTECTED]
Date: Wednesday, September 10, 2008, 2:15 PM

I have following dataset:

> res
  [,1] [,2] [,3]
 [1,] 19464 1.27
 [2,] 19465 1.27
 [3,] 19466 1.27
 [4,] 19467 1.27
 [5,] 19468 1.52
 [6,] 19469 1.52
 [7,] 1946   10 1.52
 [8,] 1946   11 1.52
 [9,] 1946   12 1.62
[10,] 19471 1.62
[11,] 19472 1.62
[12,] 19473 1.62
[13,] 19474 1.87
[14,] 19475 1.87
[15,] 19476 1.87

Now I write following code :

> as.yearmon(paste(res[,1], res[,2], sep="-"))
 [1] "Apr 1946" "May 1946" "Jun 1946" "Jul
1946" "Aug 1946" "Sep 1946" "Oct 1946"
"Nov 1946" "Dec 1946"
[10] "Jan 1947" "Feb 1947" "Mar 1947" "Apr
1947" "May 1947" "Jun 1947"
Warning message:
In if (nch == 1) "%Y-%m" else "%Y-%m-%d" :
  the condition has length > 1 and only the first element will be used

Can anyone please tell me why this warning message is coming and what is the
remedy?

Regards,

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



  
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] help: error handling in try

2008-09-11 Thread Andy Zhu
Hi, Jim:

Thanks again for replying. Sorry to confuse on saying stop the program; I mean 
program exits the function early where stop raises the error (this is inside a 
function). It seems that try doesn't fit in a function (in my old version) but 
tryCatch does (don't use stop in a function to raise error then one needs 
another function on top of it).

Not sure why try doesn't work though.

best.


--- On Wed, 9/10/08, jim holtman <[EMAIL PROTECTED]> wrote:
From: jim holtman <[EMAIL PROTECTED]>
Subject: Re: [R] help: error handling in try
To: [EMAIL PROTECTED]
Cc: r-help@r-project.org
Date: Wednesday, September 10, 2008, 9:15 PM

It does not "stop" the program.  It generates an "error"
message which
is caught by 'try' from which you can do a recovery.  The purpose of
'stop' is to cause the 'try' to catch it and return the error
message
as the result and you can test the class for being 'try-error'.

On Wed, Sep 10, 2008 at 9:11 PM, Andy Zhu <[EMAIL PROTECTED]> wrote:
> Thanks, Jim:
>
> One of the purpose of this function is to try not to stop the program and
generate T/F result for further process. Actually find fix by myself with
tryCatch (but don't know why try doesn't work). The modified function
handles potential Date and yearmon in Zoo classes.
>
> is.Date=
> # adate: a scalar value
> # fun: the date function object
> # format: the designated date format to date function
> function(adate,fun,format) {
> ret=NA;
> error.old=geterrmessage();
> .Internal(seterrmessage('no error'));
> temp=tryCatch(fun(adate,format),
> error=function(e) {
> .Internal(seterrmessage('error'))
> }
> );
> error=geterrmessage();
> if (error=='error') {
> ret=F;
> } else {
> if (is.na(temp)) {
> ret=F;
> } else {
> ret=T;
> }
> }
> .Internal(seterrmessage(error.old));
> return(ret);
> }
>
> adate='12/2000';
> fun=as.Date;
> format='%b %Y';
>
> is.Date(adate,fun,format); # false
>
> library(zoo);
> fun=as.yearmon;
> format='%m/%Y';
>
> is.Date(adate,fun,format); # true
>
> Cheer.
>
> --- On Wed, 9/10/08, jim holtman <[EMAIL PROTECTED]> wrote:
> From: jim holtman <[EMAIL PROTECTED]>
> Subject: Re: [R] help: error handling in try
> To: [EMAIL PROTECTED]
> Cc: r-help@r-project.org
> Date: Wednesday, September 10, 2008, 8:11 AM
>
> Why don't you use 'try' in this fashion:
>
>> f.error <- function(x) if (x == 1) stop('error')
>>
>> value <- try(f.error(1))
> Error in f.error(1) : error
>> if (inherits(value, 'try-error')) cat("Got this
error:",
> value) else print ("no error")
> Got this error: Error in f.error(1) : error
>> value <- try(f.error(0))  # no error
>> if (inherits(value, 'try-error')) cat ("Got this
> error:", value) else print("no error")
> [1] "no error"
>>
>>
>
>
> On Tue, Sep 9, 2008 at 8:56 PM, Andy Zhu <[EMAIL PROTECTED]>
wrote:
>> First time to post and searched archive for this problem with no clue.
My
> version is 2.5.1.
>>
>> Below is a function to check if a given date is a valid date to a
given
> date function object. It uses try (also tried tryCatch but with same
problem).
> When given an invalid date, I am hoping try will generate en error message
which
> would be picked up by the geterrmessage and thus expecting a false result.
but
> this is not the case when it is inside a function. However, if simply run
the
> body of function, the ret is indeed a false value. Why are they different?
>>
>> Many thanks
>>
>>
>> is.Date=
>> # adate: a scalar value
>> # fun: the date function object
>> # format: the designated date format to date function
>> function(adate,fun,format) {
>> ret=NA;
>> error.old=geterrmessage();
>> .Internal(seterrmessage('no error'));
>> try(fun(adate,format),silent=T);
>> error=geterrmessage();
>> if (error=='no error') {
>> ret=T;
>> } else {
>> ret=F;
>> }
>> .Internal(seterrmessage(error.old));
>> return(ret);
>> }
>>
>> adate='12/2000';
>> fun=as.Date;
>> format='%b %Y';
>>
>> is.Date(adate,fun,format) # returns 

Re: [R] Passing data among multiple instances

2009-02-04 Thread Andy Zhu


--- On Wed, 2/4/09, Feng Li <840...@gmail.com> wrote:
From: Feng Li <840...@gmail.com>
Subject: Re: [R] Passing data among multiple instances
To: "Warren Young" 
Cc: r-help@r-project.org
Date: Wednesday, February 4, 2009, 10:19 AM

On Wed, Feb 4, 2009 at 4:02 PM, Warren Young  wrote:

> Feng Li wrote:
>
>>
>> I have two R instances running at the same time,
>>
>
> On the same computer, or on different computers?

The first trial is only on my single computer with Quad CPU and more than 2G
mem.


>
>
> Is the number of Rs likely to change, or will it always be just the two?


I am planning to do three tasks at same time. That will be instance A,
instance B and instance C. There tasks are more or less the same. But one
always depends on others results.

>
>
> Is this a simple one-off problem, or are you breaking the problem up into
> pieces so you can throw lots of hardware at it?

This is just for one project. But if this is available, later I will try
more on this!


>
>
>  Is there a simpler way to pass the data in A to B?
>>
>
> Perhaps the simplest option is to write the data structure to a file,
using
> any of the several R ways to do that.  When instance 2 sees that a file is
> available, it slurps its contents in and works on it.  The hard part is
> making the second instance wait until the whole file is written out by the
> first.  You wouldn't want it to read in half the file then hit the end
> because the first process hasn't finished writing out the file.  I
don't see
> any good mechanism in R to fix this.

actually, could this be fixed this way: Instance B waits on instance A for a 
signal file. Instance A first writes the data file as usual (the file you 
mentioned above). After instance A finishes the data file, it writes a signal 
file. Instance B checks on signal file existence but it works on the data file. 
 
>
> A more robust option is to use sockets.  This is suitable even within a
> single machine.  See ?make.socket.  This solves the "how do I know
when I've
> got the full data structure problem" because the second process can
just
> keep reading until it gets an error indicating that the remote peer closed
> the connection.  Once you have the data structure in string form, you can
> eval() it to get an R object suitable for munching on.  Figuring out how
to
> pass the data might be the hardest part.  deparse() might be the easiest
> way.
>
> If you're hoping to scale this up to lots of processes, look into
Rmpi.
>  This provides a very clean way for an R program on one computer to start
> slaves on other computers and then pass data to them in native R
structures.
>  Setting up MPI itself is not trivial, however.  It's best when you
already
> have a cluster of computers linked with MPI.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Feng Li
Department of Statistics
Stockholm University
106 91 Stockholm, Sweden

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



  
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Q: rbind problem in my code

2008-10-29 Thread Andy Zhu
I have a large matrix which is divided into several pieces, manipulated 
individually, and saved into RData in disc. After each pieces are done with 
operation, I load them into memory and use rbind to stack them back into 
matrix. however, the rbind is only give me the last two pieces. The following 
code illustrates the problem: 4 pieces of matrix (1000x1000) is created and 
stored in RData; then load them back and rbind them. I would expect mat is of 
4000*1000; however, dim(mat) shows (2000 1000).

Where is my code wrong?

Thanks

## define a pathData directory
pathData='C:'\\data';

points=1000;
data.pfx='rnorm';

rname=paste('row',1:points,sep='');
cname=paste('col',1:points,sep='');

for (i in 1:4) {
    x=rnorm(points^2);
    mat=matrix(data=x,nrow=points,ncol=points);
    rname=paste('row',(points*(i-1)+1):(points*i),sep='');
    rownames(mat)=rname;
    colnames(mat)=cname;
    file.rdata=paste(pathData,'\\',data.pfx,'_',i,'.RData',
            sep='');
    save(list='mat',file=file.rdata,compress=T);
}

mat=NULL;
for (i in 1:4) {
    file.rdata=paste(pathData,'\\',data.pfx,'_',i,'.RData',
            sep='');
    x=load(file.rdata);
    mat=rbind(mat,get(x));
}

### code end here

> dim(mat)
[1] 2000 1000




  
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.