Re: [R] Errors checking a library

2004-11-18 Thread Uwe Ligges
michael watson (IAH-C) wrote:
Hi
I am writing an R library.  The documentation for one of my functions
includes an example that I *know* works - simply cut and paste into R on
either Windows and Linux and it works perfectly, no errors or warnings,
nothing, nyet.
However, when I run R CMD check on the library, I get an error.  I am
running R CMD check on linux, and the offending piece of code appears to
be:
cox[cox$group %in% onc,]
You need to quote %: \%.
Uwe Ligges

cox is a data frame, one of the columns of which is group, which
contains numbers.  onc is a vector of numbers.
The output on Linux from R CMD check is this:

# lots of code
# lots of code
cox[cox$group
+
+
+ # the rest of my code
Error: syntax error
Execution halted
As can be seen, my code cox[cox$group %in% onc,] seems to have been
executed incorrectly.  Does R CMD check have a problem with the %in%
operator?  It would seem that R has somehow got mixed up and has lost
the rest of my command.
I'm using R 1.9.1 on Suse Linux 8.2.  The example code works fine on
both Windows and Linux when cut-and-pasted into an R window.
Mick
__
[EMAIL PROTECTED] mailing list
https://stat.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://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Errors checking a library

2004-11-18 Thread Roger Bivand
On Thu, 18 Nov 2004, michael watson (IAH-C) wrote:

 Hi
 
 I am writing an R library.  The documentation for one of my functions
 includes an example that I *know* works - simply cut and paste into R on
 either Windows and Linux and it works perfectly, no errors or warnings,
 nothing, nyet.
 
 However, when I run R CMD check on the library, I get an error.  I am
 running R CMD check on linux, and the offending piece of code appears to
 be:
 
 cox[cox$group %in% onc,]
 
 cox is a data frame, one of the columns of which is group, which
 contains numbers.  onc is a vector of numbers.
 
 The output on Linux from R CMD check is this:
 
  # lots of code
  # lots of code
 cox[cox$group
 +
 +
 + # the rest of my code
 Error: syntax error
 Execution halted
 
 As can be seen, my code cox[cox$group %in% onc,] seems to have been
 executed incorrectly.  Does R CMD check have a problem with the %in%
 operator?  It would seem that R has somehow got mixed up and has lost
 the rest of my command.

I'm guessing at what you may mean, so excuse me getting it wrong. If the 
code is in an example in a help file (*.Rd, \examples{} block), then the % 
may be being interpreted as a comment character, and the remainder of the 
line not processed - see Writing R Extensions - Writing R documentation 
files - Insertions.

If that is the problem, then escaping the % by \% should fix it, that it 
what is done in src/library/base/man/match.Rd anyway.

 
 I'm using R 1.9.1 on Suse Linux 8.2.  The example code works fine on
 both Windows and Linux when cut-and-pasted into an R window.
 
 Mick
 
 __
 [EMAIL PROTECTED] mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Breiviksveien 40, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93
e-mail: [EMAIL PROTECTED]

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


Re: [R] Errors checking a library

2004-11-18 Thread Peter Dalgaard
michael watson (IAH-C) [EMAIL PROTECTED] writes:

 I am writing an R library.  

A whole library? Shouldn't you try a package first?

 The documentation for one of my functions
 includes an example that I *know* works - simply cut and paste into R on
 either Windows and Linux and it works perfectly, no errors or warnings,
 nothing, nyet.
 
 However, when I run R CMD check on the library, I get an error.  I am
 running R CMD check on linux, and the offending piece of code appears to
 be:
 
 cox[cox$group %in% onc,]
 
 cox is a data frame, one of the columns of which is group, which
 contains numbers.  onc is a vector of numbers.
 
 The output on Linux from R CMD check is this:
 
  # lots of code
  # lots of code
 cox[cox$group
 +
 +
 + # the rest of my code
 Error: syntax error
 Execution halted
 
 As can be seen, my code cox[cox$group %in% onc,] seems to have been
 executed incorrectly.  Does R CMD check have a problem with the %in%
 operator?  It would seem that R has somehow got mixed up and has lost
 the rest of my command.

Think: What is the comment character in .Rd files?

Checking out src/library/base/man/match.Rd should be enlightening, but
since you might not have R sources installed, here are the relevant
bits:

\name{match}
\alias{match}
\alias{\%in\%}
\title{Value Matching}
\description{
  \code{match} returns a vector of the positions of (first) matches of
  its first argument in its second.

  \code{\%in\%} is a more intuitive interface as a binary operator,
  which returns a logical vector indicating if there is a match or not
  for its left operand.
}
\usage{
match(x, table, nomatch = NA, incomparables = FALSE)

x \%in\% table
}

\examples{
## The intersection of two sets :
intersect - function(x, y) y[match(x, y, nomatch = 0)]
intersect(1:10,7:20)

1:10 \%in\% c(1,3,5,9)
sstr - c(c,ab,B,bba,c,@,bla,a,Ba,\%)
sstr[sstr \%in\% c(letters,LETTERS)]

\%w/o\% - function(x,y) x[!x \%in\% y] #--  x without y
(1:10) \%w/o\% c(3,7,12)
}
\keyword{manip}
 

-- 
   O__   Peter Dalgaard Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics 2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark  Ph: (+45) 35327918
~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907

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