Re: [R] How to read and write an S4 class

2009-08-12 Thread ml-r-help

see
?dput
?save


e.g.
setClass(track, representation(x=numeric, y=numeric))
x - new(track, x=1:4, y=5:8)

# save as binary
fn - tempfile()
save(x, ascii=FALSE, file=fn)
rm(x)
load(fn)
x

# save as  ASCII
save(x, ascii=TRUE, file=fn)

# ASCII text representation from which to regenerate the data
dput(x, file=fn)
y - dget(fn)


R_help Help wrote:
 Hi,
 
 I have an object in S4 class. Is there anyway that I can write to a
 file and read it back to R? Thank you.
 
 adschai
 
 __
 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.
 


-- 
Matthias Burger Project Manager/ Biostatistician
Epigenomics AGKleine Praesidentenstr. 110178 Berlin, Germany
phone:+49-30-24345-0fax:+49-30-24345-555
http://www.epigenomics.com   matthias.bur...@epigenomics.com
--
Epigenomics AG Berlin   Amtsgericht Charlottenburg HRB 75861
Vorstand:   Geert Nygaard (CEO/Vorsitzender)
Oliver Schacht PhD (CFO)
Aufsichtsrat:   Prof. Dr. Dr. hc. Rolf Krebs (Chairman/Vorsitzender)

__
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] How to stop function printing unwanted output?

2009-08-06 Thread ml-r-help
?capture.output

so with the given example this line should do what you wanted while avoiding 
the output file

dummy - capture.output(comparison - LSD.test(yield,virus,df,MSerror, 
p.adj=bonferroni,
group=FALSE, main=Yield of sweetpotato\ndealt with different virus))

Matthias

David Winsemius wrote:
 
 On Aug 6, 2009, at 12:24 PM, Erik Iverson wrote:
 
 In my example, I don't want LSD.test to print any output, I just want
 to use some of it later... How to stop it printing anything?

 ?invisible


 I'm not sure that works in this situation:

 test - function() {
  print(output)
 }

 test()
 invisible(test())

 Both of the above still print out output, which I think is the
 original problem. The invisible function will not print the value of a
 function, but if there is an explicit print call within the
 function, that will of course happen, since the value hasn't been
 returned at that point.  However, we don't know the original problem
 since LSD.test is not defined, and therefore the example is not
 reproducible.  I assume within the function, it is printing out some
 values using print or cat?  We just have to guess though.

 Maybe the answer is in ?sink ??

 
 Quite right. A search suggests that LSD.test is from package agricolae
 and it does have several points at which cat() and print() would be
 subverting my intent. So the answer would be to sink it somewhere that
 the sun does not shine and then unsink or would that be resurface?
 With the example on the LSD.test help page:
 
 sink(file=undesired.txt)
 comparison - invisible( LSD.test(yield,virus,df,MSerror,
 p.adj=bonferroni, group=FALSE,
 + main=Yield of sweetpotato\ndealt with different virus) )
 sink()
 comparison
   trtmeans M N  std.err
 1  cc 24.4   3 2.084067
 2  fc 12.86667   3 1.246774
 3  ff 36.3   3 4.233727
 4  oo 36.9   3 2.482606
 
 Erik
 
 David Winsemius, MD
 Heritage Laboratories
 West Hartford, CT
 
 __
 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.
 


-- 
Matthias Burger Project Manager/ Biostatistician
Epigenomics AGKleine Praesidentenstr. 110178 Berlin, Germany
phone:+49-30-24345-0fax:+49-30-24345-555
http://www.epigenomics.com   matthias.bur...@epigenomics.com
--
Epigenomics AG Berlin   Amtsgericht Charlottenburg HRB 75861
Vorstand:   Geert Nygaard (CEO/Vorsitzender)
Oliver Schacht PhD (CFO)
Aufsichtsrat:   Prof. Dr. Dr. hc. Rolf Krebs (Chairman/Vorsitzender)

__
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] Bug in package.skeleton, R 2.9.0?

2009-07-15 Thread ml-r-help
Daniel Klevebring wrote:
 Bump
 
 Anyone?
 
 Thanks
 Daniel
 
 On 13 jul 2009, at 10.57, Daniel Klevebring wrote:
 
 Dear all,

 I am using package.skeleton to build a small packages of misc function
 for personal use. I have recently discovered that the option
 force=TRUE doesn't seem to do what is meant to do. Here's what I'm
 doing:

 setwd(/Users/danielk/Documents/R/packages/dk)
 files - paste(codebase, dir(codebase, pattern=.R), sep=/)
 package.skeleton(name=dk, force=TRUE, code_files=files)
 Creating directories ...
 Creating DESCRIPTION ...
 Creating Read-and-delete-me ...
 Copying code files ...
 Making help files ...
 Done.
 Further steps are described in './dk/Read-and-delete-me'.
 Now, everything seems fine, but changes to files in me codebase
 folder, doesn't come along if the folder dk/R already contains the
 files, even though I use force=TRUE. If I remove the dk/R folder or
 the dk folder altogether, the changes come along so to me it seems
 that it's the overwrite part that doesn't work as it should - or am I
 doing something wrong here? To me, it seems that the function
 safe.dir.create (which is defined in package.skeleton never overwrites
 folders, yielding force=TRUE useless.

from the help on package.skeleton

force: If 'FALSE' will not overwrite an existing directory.

which could be clearer in that package.skeleton will stop with an error if the 
top level
directory, i.e. 'dk' in your case, exists and you had specified force=FALSE. 
But it will
not overwrite the existing directory 'dk' with force=TRUE as you observed.

Looking at the code it is clear that file.copy is used to copy the code files 
and that has
per default overwrite=FALSE so your existing code files will not be overwritten.
With the current implementation package.skeleton will not do what you intended.

There are many ways to workaround
e.g.
fn - dir(codebase, pattern=.R, full.names=TRUE)
file.remove( list.files(path=file.path(dk, R), pattern=\\.R, 
full.names=TRUE))
package.skeleton(name=dk, force=TRUE, code_files=fn)


Matthias

 See below for sessionInfo.

 Thanks a bunch
 Daniel



 sessionInfo()
 R version 2.9.0 (2009-04-17)
 i386-apple-darwin8.11.1

 locale:
 en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

 attached base packages:
 [1] stats graphics  grDevices utils datasets  methods   base

 loaded via a namespace (and not attached):
 [1] tools_2.9.0

 --

 Contact information:

 Daniel Klevebring
 M. Sc. Eng., Ph.D. Student
 Dept of Gene Technology
 Royal Institute of Technology, KTH
 SE-106 91 Stockholm, Sweden

 Visiting address: Roslagstullsbacken 21, B3
 Delivery address: Roslagsvägen 30B, 104 06, Stockholm
 Invoice address: KTH Fakturaserice, Ref DAKL KTHBIO, Box 24075,
 SE-10450 Stockholm
 E-mail: dan...@biotech.kth.se
 Phone: +46 8 5537 8337 (Office)
 Phone: +46 704 71 65 91 (Mobile)
 Web: http://www.biotech.kth.se/genetech/index.html
 Fax: +46 8 5537 8481

 --

 Contact information:

 Daniel Klevebring
 M. Sc. Eng., Ph.D. Student
 Dept of Gene Technology
 Royal Institute of Technology, KTH
 SE-106 91 Stockholm, Sweden

 Visiting address: Roslagstullsbacken 21, B3
 Delivery address: Roslagsvägen 30B, 104 06, Stockholm
 Invoice address: KTH Fakturaserice, Ref DAKL KTHBIO, Box 24075,
 SE-10450 Stockholm
 E-mail: dan...@biotech.kth.se
 Phone: +46 8 5537 8337 (Office)
 Phone: +46 704 71 65 91 (Mobile)
 Web: http://www.biotech.kth.se/genetech/index.html
 Fax: +46 8 5537 8481
 MSN messenger: klevebr...@msn.com


  [[alternative HTML version deleted]]

 ATT1.txt
 
 --
 
 Contact information:
 
 Daniel Klevebring
 M. Sc. Eng., Ph.D. Student
 Dept of Gene Technology
 Royal Institute of Technology, KTH
 SE-106 91 Stockholm, Sweden
 
 Visiting address: Roslagstullsbacken 21, B3
 Delivery address: Roslagsvägen 30B, 104 06, Stockholm
 Invoice address: KTH Fakturaserice, Ref DAKL KTHBIO, Box 24075,  
 SE-10450 Stockholm
 E-mail: dan...@biotech.kth.se
 Phone: +46 8 5537 8337 (Office)
 Phone: +46 704 71 65 91 (Mobile)
 Web: http://www.biotech.kth.se/genetech/index.html
 Fax: +46 8 5537 8481
 MSN messenger: klevebr...@msn.com
 
 
   [[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.


-- 
Matthias Burger Project Manager/ Biostatistician
Epigenomics AGKleine Praesidentenstr. 110178 Berlin, Germany
phone:+49-30-24345-0fax:+49-30-24345-555
http://www.epigenomics.com   matthias.bur...@epigenomics.com
--
Epigenomics AG Berlin   Amtsgericht Charlottenburg HRB 75861
Vorstand:   Geert Nygaard (CEO/Vorsitzender)
Oliver Schacht 

Re: [R] if condition doesn't evaluate to True/False

2009-04-29 Thread ml-r-help
see
?is.null

e.g.
if( is.null(sub_grp_whr_cls_data[sbgrp_no, 1]) )
{
  your code
}

Moumita Das wrote:
 Hi friends,
 Please help me with this bug.
 
 *Bug in my code:*
 
 In this variable sub_grp_whr_cls_data[sbgrp_no,1] I store the where
 clause.every sub group has a where condition linked with it.
 
 Database1
 
 
 Where clause  was  not found for a particular subgroup,
 sub_grp_whr_cls_data[sbgrp_no,1]  value was NULL
 
 So the condition (*sub_grp_whr_cls_data[sbgrp_no,1]==NULL ||
 sub_grp_whr_cls_data[sbgrp_no,1]==*) should evaluate to TRUE ,but it
 evaluated to NA
 
 So the if block where I used the the condition threw error
 
 If(*sub_grp_whr_cls_data[sbgrp_no,1]==NULL ||
 sub_grp_whr_cls_data[sbgrp_no,1]==*)
 
 i.e if(NA)
 
 Error:--
 
 Error in if (sub_grp_whr_cls_data[sbgrp_no, 1] == NULL ||
 sub_grp_whr_cls_data[sbgrp_no,  :
 
   missing value where TRUE/FALSE needed
 
 Comments:-- but when there ‘s no where clause value the condition
 (sub_grp_whr_cls_data[sbgrp_no,1]==NULL
 ||sub_grp_whr_cls_data[sbgrp_no,1]==) should automatically evaluate to *
 TRUE*
 
 
 
 Database2
 
 Where clause  was  found for a particular subgroup
 
 The condition (sub_grp_whr_cls_data[sbgrp_no,1]==NULL
 ||sub_grp_whr_cls_data[sbgrp_no,1]==) evaluated to FALSE
 
 So if (sub_grp_whr_cls_data[sbgrp_no,1]==NULL
 ||sub_grp_whr_cls_data[sbgrp_no,1]==) is
 
 If (FALSE) ,control goes to the else part.
 
 This is exactly what is expected of the program.
 
 *QUERY:-- **If the condition evaluates to FALSE  when a where condition is
 available why doesn’t it evaluate to TRUE when a where condition available
 is NULL or no where condition is available.*
 
 Here I have taken the example of two databases where I tried to get the
 where clause for subgroup 1.In case of Database1 it was not available in
 case of Databse2 it was available.But the problem may appear for the same
 database also, when where clause is available for say one subgroup and not
 for the other.
 
 
 
 
 
 __
 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.


-- 
Matthias Burger Project Manager/ Biostatistician
Epigenomics AGKleine Praesidentenstr. 110178 Berlin, Germany
phone:+49-30-24345-0fax:+49-30-24345-555
http://www.epigenomics.com   matthias.bur...@epigenomics.com
--
Epigenomics AG Berlin   Amtsgericht Charlottenburg HRB 75861
Vorstand:   Geert Nygaard (CEO/Vorsitzender)
Oliver Schacht PhD (CFO)
Aufsichtsrat:   Prof. Dr. Dr. hc. Rolf Krebs (Chairman/Vorsitzender)

__
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] if condition doesn't evaluate to True/False

2009-04-29 Thread ml-r-help
Petr PIKAL wrote:
 Hi
 
 r-help-boun...@r-project.org napsal dne 29.04.2009 17:05:01:
 
 see
 ?is.null

 e.g.
 if( is.null(sub_grp_whr_cls_data[sbgrp_no, 1]) )
 {
   your code
 }
 
 It probably will not work as 
 
 sub_grp_whr_cls_data[sbgrp_no,1]==NULL
 
 implicates that there is character value NULL. I am not sure if you can 
 get NULL as a part of some object. I tried and failed.
 See what you get
 x- c(1,2,3, NULL)
 
 Regards
 Petr

thanks for pointing this out clearly, I had thought only about making the 
comparison
return a logical for use in the expression.

On hindsight it seems implausible to ever get NULL in the matrix/data frame.

(DONT USE
playing around I found the following abuse to work
m - as.data.frame(diag(3))
m[[3]][3] - list(NULL)
is.null(m[3,3][[1]])
[1] TRUE
)
Regards,
  Matthias

 
 Moumita Das wrote:
 Hi friends,
 Please help me with this bug.

 *Bug in my code:*

 In this variable sub_grp_whr_cls_data[sbgrp_no,1] I store the where
 clause.every sub group has a where condition linked with it.

 Database1


 Where clause  was  not found for a particular subgroup,
 sub_grp_whr_cls_data[sbgrp_no,1]  value was NULL

 So the condition (*sub_grp_whr_cls_data[sbgrp_no,1]==NULL ||
 sub_grp_whr_cls_data[sbgrp_no,1]==*) should evaluate to TRUE ,but it
 evaluated to NA

 So the if block where I used the the condition threw error

 If(*sub_grp_whr_cls_data[sbgrp_no,1]==NULL ||
 sub_grp_whr_cls_data[sbgrp_no,1]==*)

 i.e if(NA)

 Error:--

 Error in if (sub_grp_whr_cls_data[sbgrp_no, 1] == NULL ||
 sub_grp_whr_cls_data[sbgrp_no,  :

   missing value where TRUE/FALSE needed

 Comments:-- but when there ‘s no where clause value the condition
 (sub_grp_whr_cls_data[sbgrp_no,1]==NULL
 ||sub_grp_whr_cls_data[sbgrp_no,1]==) should automatically evaluate 
 to *
 TRUE*



 Database2

 Where clause  was  found for a particular subgroup

 The condition (sub_grp_whr_cls_data[sbgrp_no,1]==NULL
 ||sub_grp_whr_cls_data[sbgrp_no,1]==) evaluated to FALSE

 So if (sub_grp_whr_cls_data[sbgrp_no,1]==NULL
 ||sub_grp_whr_cls_data[sbgrp_no,1]==) is

 If (FALSE) ,control goes to the else part.

 This is exactly what is expected of the program.

 *QUERY:-- **If the condition evaluates to FALSE  when a where 
 condition is
 available why doesn’t it evaluate to TRUE when a where condition 
 available
 is NULL or no where condition is available.*

 Here I have taken the example of two databases where I tried to get 
 the
 where clause for subgroup 1.In case of Database1 it was not available 
 in
 case of Databse2 it was available.But the problem may appear for the 
 same
 database also, when where clause is available for say one subgroup and 
 not
 for the other.




 
 __
 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.

 -- 
 Matthias Burger Project Manager/ Biostatistician
 Epigenomics AGKleine Praesidentenstr. 110178 Berlin, Germany
 phone:+49-30-24345-0fax:+49-30-24345-555
 http://www.epigenomics.com   matthias.bur...@epigenomics.com
 --
 Epigenomics AG Berlin   Amtsgericht Charlottenburg HRB 75861
 Vorstand:   Geert Nygaard (CEO/Vorsitzender)
 Oliver Schacht PhD (CFO)
 Aufsichtsrat:   Prof. Dr. Dr. hc. Rolf Krebs (Chairman/Vorsitzender)

 __
 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@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.


-- 
Matthias Burger Project Manager/ Biostatistician
Epigenomics AGKleine Praesidentenstr. 110178 Berlin, Germany
phone:+49-30-24345-0fax:+49-30-24345-555
http://www.epigenomics.com   matthias.bur...@epigenomics.com
--
Epigenomics AG Berlin   Amtsgericht Charlottenburg HRB 75861
Vorstand:   Geert Nygaard (CEO/Vorsitzender)
Oliver Schacht PhD (CFO)
Aufsichtsrat:   Prof. Dr. Dr. hc. Rolf Krebs (Chairman/Vorsitzender)

__
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, 

Re: [R] Error in var(x, na.rm = na.rm) : no complete element pairs

2009-03-05 Thread ml-r-help
Carlos Morales wrote:
 Hello,
 
 I still have the same error which I have written in the Subject field, I 
 leave here the code and I hope you can help me with this:
 
[removed]

the lengthy code example does not make it easier to help you, in particular 
without the
data you used. All the commented out code should have been removed before 
posting.
My guess is that you use R  2.8.0 and generate a vector s which contains only 
NAs.
Try to inspect your function filter.clones by putting a browser()
call somewhere before the sd() call and run it again.
See ?browser and ?trace.

And you could vectorize this (and other parts), e.g.
the last loop would be rewritten as

tripliclones.info$Estandar_desviation - apply(tripliclones.info[ ,2:4], 1, 
function(x)
sd(as.numeric(x), na.rm=TRUE))

Regards, Matthias


R version 2.7.1 (2008-06-23)
 b - rep(NA,4)
 sd(b)
Error in var(x, na.rm = na.rm) : missing observations in cov/cor
 sd(b, TRUE)
Error in var(x, na.rm = na.rm) : no complete element pairs


R version 2.8.1 (2008-12-22)
 b- rep(NA,4)
 sd(b)
[1] NA
 sd(b, TRUE)
[1] NA

-- 
Matthias Burger Project Manager/ Biostatistician
Epigenomics AGKleine Praesidentenstr. 110178 Berlin, Germany
phone:+49-30-24345-0fax:+49-30-24345-555
http://www.epigenomics.com   matthias.bur...@epigenomics.com
--
Epigenomics AG Berlin   Amtsgericht Charlottenburg HRB 75861
Vorstand:   Geert Nygaard (CEO/Vorsitzender)
Oliver Schacht PhD (CFO)
Aufsichtsrat:   Prof. Dr. Dr. hc. Rolf Krebs (Chairman/Vorsitzender)

__
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 package tests

2009-01-15 Thread ml-r-help
Hi Nathan,

in addition to what others have already mentioned there is some documentation
in the Writing R Extensions Manual:
- on the supported structure of packages, indicating where test code might be 
added
 
http://stat.ethz.ch/R-manual/R-patched/doc/manual/R-exts.html#Package-subdirectories
- and the recommended standard approach to check a package
http://stat.ethz.ch/R-manual/R-patched/doc/manual/R-exts.html#Checking-and-building-packages

and a wiki article on how to combine the standard check (viz R CMD check) with 
any of the
unit testing approaches
http://wiki.r-project.org/rwiki/doku.php?id=developers:runits=unit%20test

Examples for the standard approach employed by R can be found
in the R source repository
https://svn.r-project.org/R/trunk/src/library/stats/tests/

and for unit test based checking
e.g. Rmetrics
http://r-forge.r-project.org/plugins/scmsvn/viewcvs.php/pkg/?root=rmetrics

or BioConductor examples
https://hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/Biobase/inst/UnitTests/
where you need the access info provided here
http://wiki.fhcrc.org/bioc/DeveloperPage


Regards,

 Matthias

Nathan S. Watson-Haigh wrote:
 I was wondering if anyone could point me in the right direction for reading 
 up on writing tests in
 R. I'm writing some functions for inclusion into a package and would like to 
 test them to ensure
 they're doing what I expect them to do.
 
 Are these approaches used for testing packages in CRAN?
 
 Cheers,
 Nathan
 
 

__
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.



-- 
Matthias Burger Project Manager/ Biostatistician
Epigenomics AGKleine Praesidentenstr. 110178 Berlin, Germany
phone:+49-30-24345-371  fax:+49-30-24345-555
http://www.epigenomics.com   matthias.bur...@epigenomics.com
--
Epigenomics AG Berlin   Amtsgericht Charlottenburg HRB 75861
Vorstand:   Geert Nygaard (CEO/Vorsitzender)
Oliver Schacht PhD (CFO)
Aufsichtsrat:   Prof. Dr. Dr. hc. Rolf Krebs (Chairman/Vorsitzender)

__
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.