Re: [Rd] "warning: assignment discards qualifiers from pointer target type"

From: Jeffrey Ryan <jeffrey.ryan_at_lemnica.com>
Date: Wed, 08 Jun 2011 21:11:00 -0500

On Wed, Jun 8, 2011 at 7:17 PM, oliver <oliver_at_first.in-berlin.de> wrote:

> On Wed, Jun 08, 2011 at 02:23:29PM -0400, Simon Urbanek wrote:
> >
> > On Jun 8, 2011, at 12:08 PM, oliver wrote:
> >
> > > On Wed, Jun 08, 2011 at 12:22:10PM +0100, Prof Brian Ripley wrote:
> > >> On Tue, 7 Jun 2011, Duncan Murdoch wrote:
> > >>
> > >>> On 07/06/2011 9:08 AM, oliver wrote:
> > >>>> Hello,
> > >>>>
> > >>>> following an advice here from the list I looked into sources of
> other
> > >>>> packages (xts) and found the TYPEOF() macro/function, which really
> is
> > >>>> helpful.
> > >>
> > >> It is documented, of course, but actually better alternatives are
> > >> described in 'Writing R Extensions'.
> > >>
> > >> We would urge you to study the R sources rather than copy bad habits
> > >> from randomly chosen package sources.
> > > [...]
> > >
> > > Hmhh, it was not randomly chosen, it was, what I got as a hint here on
> the list.
> > >
> >
> > It was not provided to you to look at how it checks arguments. For basic
> > usage it's better to look at the R code. The coding styles vary a lot in
> > packages (and so does the quality of packages) - some of them are really
> bad,
> > but you have to remember that most people write packages in their free
> time and
> > are not programmers...

>

> OK, I see.

>

Of course - most of R core aren't "programmers" either - whatever that means. Statisticians, mathematicians, etc...

;-)

Most contributed packages aren't meant to be case studies in a comp-sci class either, they are meant to solve real world problems - problems that many of us work on daily.

That said, I'd also say look to R sources first, but since many things in R core aren't available in the API - you aren't really able to copy the 'best practices' alluded to. And sometimes you've got to bootstrap solutions when the list is otherwise silent. Another reason that you should look outside of R sources in addition to inside of them is that the community code is far more abundant that the core code. Sort of like theory vs. practice - they only teach so much in school.

For reference, TYPEOF is straight from R source (of course):

http://svn.r-project.org/R/trunk/src/main/subset.c

Cheers,
Jeff

>
>

> [...]
> > >> and there is no
> > >> check in that code that LENGTH(filename_sexp) > 0 (or == 1). In the
> > >> R sources you will often see things like
> > >>
> > >> if(!isString(sfile) || LENGTH(sfile) < 1)
> > >> error("invalid '%s' argument", "description");
> > > [...]
> > >
> > > If it's a vector, I can just pic the first element.
> >
> > Yes, but only if it's not a vector of length zero - hence the necessary
> check.
> >
> >
> > > Or does LENGTH(sfile) give the length of the string itself
> > > (like strlen(3))?
> > >
> >
> > No.
> [...]
>

> OK, I looked at this now.
>

> LENGTH() checks the length of the vector.
>

> Good to know this.
>

> So the problem of a vector of length 0 can be with any arguments of type
> SEXP,
> hence I will need to check ANY arg on it's length.
>

> This is vital to stability under any situation.
>

> Thanks for this valuable hint!
>

> I will add checks for all my SEXP-args.
>
>

> Ciao,
> Oliver
>

> ______________________________________________
> R-devel_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
-- 
Jeffrey Ryan
jeffrey.ryan_at_lemnica.com

www.lemnica.com
www.esotericR.com

	[[alternative HTML version deleted]]

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Thu 09 Jun 2011 - 02:15:16 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 09 Jun 2011 - 11:40:18 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive