Re: [R] help(package)->sink()

2004-07-26 Thread Prof Brian Ripley
On Sun, 25 Jul 2004, Thomas Lumley wrote:

> On Sat, 24 Jul 2004, Spencer Graves wrote:
> 
> >
> >   4.  A request for "packageInfo.print" returned "object ... not
> > found".
> 
> I think someone may have been contaminated by Java or some such. It should
> be print.packageInfo
> 
> >  A request for class(mclustInfo) confirmed that it was a
> > packageInfo object, so I tried getMethod("print",  "packageInfo");   I
> > got, 'No generic function defined for "print"'.  Then I tried,
> > getMethod("show", "packageInfo");  I got, 'No method defined for
> > function "show" and signature object = "packageInfo"'.
> >
> 
> For S3 methods you need getS3method("print","packageInfo") rather than
> getMethod.
> 
> People often recommend getAnywhere("print.packageInfo"), which does take
> less typing, but I prefer getS3method.

They are not exactly equivalent, though.  Although I know of no actual
examples, it is possible to register something like printPackageInfo() as
the S3 method for print() for class "packageInfo".  Then getS3method will
work and getAnywhere will not.

The advantage of getAnywhere is that it is blunderbuss designed to pick up 
all possible matches for any sort of R object, which can be useful.

-- 
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] help(package)->sink()

2004-07-25 Thread Thomas Lumley
On Sat, 24 Jul 2004, Spencer Graves wrote:

>
>   4.  A request for "packageInfo.print" returned "object ... not
> found".

I think someone may have been contaminated by Java or some such. It should
be print.packageInfo

>A request for class(mclustInfo) confirmed that it was a
> packageInfo object, so I tried getMethod("print",  "packageInfo");   I
> got, 'No generic function defined for "print"'.  Then I tried,
> getMethod("show", "packageInfo");  I got, 'No method defined for
> function "show" and signature object = "packageInfo"'.
>

For S3 methods you need getS3method("print","packageInfo") rather than
getMethod.

People often recommend getAnywhere("print.packageInfo"), which does take
less typing, but I prefer getS3method.

-thomas

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] help(package)->sink()

2004-07-25 Thread Spencer Graves
Hi, Gabor: 

 1.  Thanks.  I failed to put "mypager.bat" in "/".  After I moved 
it, I get the following: 

> readLines("/mypager.bat")
[1] "type %1 > /mclust.txt"
> old <- options()
> options(pager = "/mypager.bat")
> help(package = "mclust")
> options(old) # reset options back if finished
> head(readLines("/myfile.txt")) 
Error in file(con, "r") : unable to open connection
In addition: Warning message:
cannot open file `/myfile.txt'

 While R couldn't find the file, it was there, and contained all 
the necessary information. 

 4.  Thanks for the tip on print.packageInfo:  It worked.  [On 
other occasions, I've done things like this routinely.  I got 
sidetracked with the S4 search and frustrated with my failure to get 
much out of that, with the result that I failed to see the obvious.]

 Vielen Dank noch einmal
 spencer graves
Gabor Grothendieck wrote:
Spencer Graves  pdf.com> writes:
:   1.  I failed to make method 1 work, though I've done that kind of 
: thing in the past, and I believe I could make it work if I had to. 
: 

I am using R 1.9.1 patched on Windows XP and at least there it seems
to work.  I did notice that I put a forward slash in the type statement
whereas I meant a backward slash although the forward slash worked anyways,
at least on my system.  Here is the output of an R session:
R> readLines("/mypager.bat")  # check content of mypager.bat file
[1] "type %1 > /myfile.txt"
R> old <- options()
R> options(pager = "/mypager.bat")
R> help(package = "mclust")
R> options(old) # reset options back if finished
R> head(readLines("/myfile.txt"))  # check 1st few lines of myfile.txt
[1] ""  "   Information on 
Package 'mclust'"
[3] ""  "Description:" 
[5] ""  "Package: mclust"  
R> R.version.string
[1] "R version 1.9.1, 2004-07-13"

:   4.  A request for "packageInfo.print" returned "object ... not 
: found".  A request for class(mclustInfo) confirmed that it was a 
: packageInfo object, so I tried getMethod("print",  "packageInfo");   I 
: got, 'No generic function defined for "print"'.  Then I tried, 
: getMethod("show", "packageInfo");  I got, 'No method defined for 
: function "show" and signature object = "packageInfo"'. 

Sorry about that.  I should have written print.packageInfo  since
the syntax of these things is genericmethod.class and print is the 
generic method and packageInfo is the class.

: Gabor Grothendieck wrote:
: 
: >Spencer Graves  pdf.com> writes:
: >
: >: 
: >: I wanted to direct packageInfo to a file, so I could add comments, 
: >: e.g., in MS Word.  The following command stored the desired information 
: >: in an object: 
: >: 
: >:   mclustInfo <- help(package="mclust")
: >: 
: >:   Then "mclustInfo" displays it on my screen.  To direct it to a 
: >: file, I tried the following: 
: >: 
: >:   sink("mclust.txt")
: >:   mclustInfo
: >:   sink()
: >: 
: >:   This sequence created an empty file "mclust.txt", while displaying 
: >: mclustInfo on my screen.  After a few more failed attempts, I gave up 
: >: trying to be clever and copied the text from the screen into Word. 
: >
: >In addition to your copy and paste solution:
: >
: >1. You could intercept the file.show output by redefining the pager:
: >
: >   a. create a one line file called mypager.bat in \ with this line:
: >
: >  type %1 > /mclust.txt
: >
: >   (with appropriate modifications if you are using UNIX).
: >
: >   b. In R issue these commands:
: >
: >  old <- options()
: >  options(pager = "/mypager.bat")
: >  help(package = "mclust")
: >  options(old) # reset options back if finished
: >
: >2. Don't use R but go right to the DESCRIPTION and INDEX
: >   files.  getwd("library/mclust") should show you where
: >   to find them.
: >
: >3. If you don't care about the formatting:
: >
: >  sink("/mclust.txt")
: >  writeLines(unlist(help(package="mclust")$info))
: >  sink()
: >
: >4. You could modify packageInfo.print adding a file= argument.
: >
: >__
: >R-help  stat.math.ethz.ch mailing list
: >https://www.stat.math.ethz.ch/mailman/listinfo/r-help
: >PLEASE do read the posting guide! http://www.R-project.org/posting-
guide.html
: >  
: >
: 
: __
: R-help  stat.math.ethz.ch mailing list
: https://www.stat.math.ethz.ch/mailman/listinfo/r-help
: PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
: 
:

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
 

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://w

Re: [R] help(package)->sink()

2004-07-24 Thread Gabor Grothendieck
Spencer Graves  pdf.com> writes:

:   1.  I failed to make method 1 work, though I've done that kind of 
: thing in the past, and I believe I could make it work if I had to. 
: 

I am using R 1.9.1 patched on Windows XP and at least there it seems
to work.  I did notice that I put a forward slash in the type statement
whereas I meant a backward slash although the forward slash worked anyways,
at least on my system.  Here is the output of an R session:

R> readLines("/mypager.bat")  # check content of mypager.bat file
[1] "type %1 > /myfile.txt"
R> old <- options()
R> options(pager = "/mypager.bat")
R> help(package = "mclust")
R> options(old) # reset options back if finished
R> head(readLines("/myfile.txt"))  # check 1st few lines of myfile.txt
[1] ""  "   Information on 
Package 'mclust'"
[3] ""  "Description:" 
[5] ""  "Package: mclust"  
R> R.version.string
[1] "R version 1.9.1, 2004-07-13"

:   4.  A request for "packageInfo.print" returned "object ... not 
: found".  A request for class(mclustInfo) confirmed that it was a 
: packageInfo object, so I tried getMethod("print",  "packageInfo");   I 
: got, 'No generic function defined for "print"'.  Then I tried, 
: getMethod("show", "packageInfo");  I got, 'No method defined for 
: function "show" and signature object = "packageInfo"'. 

Sorry about that.  I should have written print.packageInfo  since
the syntax of these things is genericmethod.class and print is the 
generic method and packageInfo is the class.

 
: Gabor Grothendieck wrote:
: 
: >Spencer Graves  pdf.com> writes:
: >
: >: 
: >: I wanted to direct packageInfo to a file, so I could add comments, 
: >: e.g., in MS Word.  The following command stored the desired information 
: >: in an object: 
: >: 
: >:   mclustInfo <- help(package="mclust")
: >: 
: >:   Then "mclustInfo" displays it on my screen.  To direct it to a 
: >: file, I tried the following: 
: >: 
: >:   sink("mclust.txt")
: >:   mclustInfo
: >:   sink()
: >: 
: >:   This sequence created an empty file "mclust.txt", while displaying 
: >: mclustInfo on my screen.  After a few more failed attempts, I gave up 
: >: trying to be clever and copied the text from the screen into Word. 
: >
: >In addition to your copy and paste solution:
: >
: >1. You could intercept the file.show output by redefining the pager:
: >
: >   a. create a one line file called mypager.bat in \ with this line:
: >
: >  type %1 > /mclust.txt
: >
: >   (with appropriate modifications if you are using UNIX).
: >
: >   b. In R issue these commands:
: >
: >  old <- options()
: >  options(pager = "/mypager.bat")
: >  help(package = "mclust")
: >  options(old) # reset options back if finished
: >
: >2. Don't use R but go right to the DESCRIPTION and INDEX
: >   files.  getwd("library/mclust") should show you where
: >   to find them.
: >
: >3. If you don't care about the formatting:
: >
: >  sink("/mclust.txt")
: >  writeLines(unlist(help(package="mclust")$info))
: >  sink()
: >
: >4. You could modify packageInfo.print adding a file= argument.
: >
: >__
: >R-help  stat.math.ethz.ch mailing list
: >https://www.stat.math.ethz.ch/mailman/listinfo/r-help
: >PLEASE do read the posting guide! http://www.R-project.org/posting-
guide.html
: >  
: >
: 
: __
: R-help  stat.math.ethz.ch mailing list
: https://www.stat.math.ethz.ch/mailman/listinfo/r-help
: PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
: 
:

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] help(package)->sink()

2004-07-24 Thread Spencer Graves
 Thanks to Tom Lumley and Duncan Murdoch for explaining that this 
was a feature not a bug and to Gabor Grothendieck for providing several 
ways to get around the problem.  (Please excuse, Gabor:  I should have 
said I was using R 1.9.1 under Windows 2000.) 

 1.  I failed to make method 1 work, though I've done that kind of 
thing in the past, and I believe I could make it work if I had to. 
   
 2.  I found the DESCRIPTION and INDEX files.  Thanks much.  That 
not only answers this immediate question, it help me understand how R 
packages are structured, which will help me solve many related problems 
in the future. 

 3.  Before I sent the email, I tried dump("mclustInfo", 
"mclust.txt").  That worked, but I did not like the formatting.  I 
should have reported that in my email. 

 4.  A request for "packageInfo.print" returned "object ... not 
found".  A request for class(mclustInfo) confirmed that it was a 
packageInfo object, so I tried getMethod("print",  "packageInfo");   I 
got, 'No generic function defined for "print"'.  Then I tried, 
getMethod("show", "packageInfo");  I got, 'No method defined for 
function "show" and signature object = "packageInfo"'. 

 Anyway, I now have more than one method that works. 
 thanks again.  spencer graves

Gabor Grothendieck wrote:
Spencer Graves  pdf.com> writes:
: 
: I wanted to direct packageInfo to a file, so I could add comments, 
: e.g., in MS Word.  The following command stored the desired information 
: in an object: 
: 
:   mclustInfo <- help(package="mclust")
: 
:   Then "mclustInfo" displays it on my screen.  To direct it to a 
: file, I tried the following: 
: 
:   sink("mclust.txt")
:   mclustInfo
:   sink()
: 
:   This sequence created an empty file "mclust.txt", while displaying 
: mclustInfo on my screen.  After a few more failed attempts, I gave up 
: trying to be clever and copied the text from the screen into Word. 

In addition to your copy and paste solution:
1. You could intercept the file.show output by redefining the pager:
  a. create a one line file called mypager.bat in \ with this line:
 type %1 > /mclust.txt
  (with appropriate modifications if you are using UNIX).
  b. In R issue these commands:
 old <- options()
 options(pager = "/mypager.bat")
 help(package = "mclust")
 options(old) # reset options back if finished
2. Don't use R but go right to the DESCRIPTION and INDEX
  files.  getwd("library/mclust") should show you where
  to find them.
3. If you don't care about the formatting:
 sink("/mclust.txt")
 writeLines(unlist(help(package="mclust")$info))
 sink()
4. You could modify packageInfo.print adding a file= argument.
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
 

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] help(package)->sink()

2004-07-24 Thread Gabor Grothendieck
Spencer Graves  pdf.com> writes:

: 
: I wanted to direct packageInfo to a file, so I could add comments, 
: e.g., in MS Word.  The following command stored the desired information 
: in an object: 
: 
:   mclustInfo <- help(package="mclust")
: 
:   Then "mclustInfo" displays it on my screen.  To direct it to a 
: file, I tried the following: 
: 
:   sink("mclust.txt")
:   mclustInfo
:   sink()
: 
:   This sequence created an empty file "mclust.txt", while displaying 
: mclustInfo on my screen.  After a few more failed attempts, I gave up 
: trying to be clever and copied the text from the screen into Word. 

In addition to your copy and paste solution:

1. You could intercept the file.show output by redefining the pager:

   a. create a one line file called mypager.bat in \ with this line:

  type %1 > /mclust.txt

   (with appropriate modifications if you are using UNIX).

   b. In R issue these commands:

  old <- options()
  options(pager = "/mypager.bat")
  help(package = "mclust")
  options(old) # reset options back if finished

2. Don't use R but go right to the DESCRIPTION and INDEX
   files.  getwd("library/mclust") should show you where
   to find them.

3. If you don't care about the formatting:

  sink("/mclust.txt")
  writeLines(unlist(help(package="mclust")$info))
  sink()

4. You could modify packageInfo.print adding a file= argument.

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] help(package)->sink()

2004-07-24 Thread Duncan Murdoch
On Sat, 24 Jul 2004 10:06:02 -0700, Spencer Graves
<[EMAIL PROTECTED]> wrote:

>  I wanted to direct packageInfo to a file, so I could add comments, 
>e.g., in MS Word.  The following command stored the desired information 
>in an object: 
>
>  mclustInfo <- help(package="mclust")
>
>  Then "mclustInfo" displays it on my screen.  To direct it to a 
>file, I tried the following: 
>
>  sink("mclust.txt")
>  mclustInfo
>  sink()
>
>  This sequence created an empty file "mclust.txt", while displaying 
>mclustInfo on my screen.  After a few more failed attempts, I gave up 
>trying to be clever and copied the text from the screen into Word. 
>
>  Is this a bug, that sink does not capture the output of objects of 
>class packageInfo? 

I don't think so.  The print method for that class calls other code to
display it; it doesn't go through the regular "display to console"
route.  Instead, it writes the help page to a file, then calls
file.show.  

It's possible that on some systems file.show would just dump the file
to the console, but that's not what happens on Windows, for example.

Duncan Murdoch

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] help(package)->sink()

2004-07-24 Thread Thomas Lumley
On Sat, 24 Jul 2004, Spencer Graves wrote:

>   I wanted to direct packageInfo to a file, so I could add comments,
> e.g., in MS Word.  The following command stored the desired information
> in an object:
>
>   mclustInfo <- help(package="mclust")
>
>   Then "mclustInfo" displays it on my screen.  To direct it to a
> file, I tried the following:
>
>   sink("mclust.txt")
>   mclustInfo
>   sink()
>
>   This sequence created an empty file "mclust.txt", while displaying
> mclustInfo on my screen.  After a few more failed attempts, I gave up
> trying to be clever and copied the text from the screen into Word.
>
>   Is this a bug, that sink does not capture the output of objects of
> class packageInfo?
>

Not really.  The output doesn't really appear on your screen, it appears
on your pager.  In your case the pager is the screen, so this isn't
obvious.


-thomas

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] help(package)->sink()

2004-07-24 Thread Spencer Graves
 I wanted to direct packageInfo to a file, so I could add comments, 
e.g., in MS Word.  The following command stored the desired information 
in an object: 

 mclustInfo <- help(package="mclust")
 Then "mclustInfo" displays it on my screen.  To direct it to a 
file, I tried the following: 

 sink("mclust.txt")
 mclustInfo
 sink()
 This sequence created an empty file "mclust.txt", while displaying 
mclustInfo on my screen.  After a few more failed attempts, I gave up 
trying to be clever and copied the text from the screen into Word. 

 Is this a bug, that sink does not capture the output of objects of 
class packageInfo? 

 Best Wishes,
 spencer graves
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html