From charlie at stat.umn.edu  Fri May 13 21:44:55 2005
From: charlie at stat.umn.edu (Charles Geyer)
Date: Fri May 13 21:45:07 2005
Subject: [Rd] add Rvsnprintf to API ??
In-Reply-To: <200505131003.j4DA3BSZ020947@hypatia.math.ethz.ch>
References: <200505131003.j4DA3BSZ020947@hypatia.math.ethz.ch>
Message-ID: <20050513194455.GA23627@stat.umn.edu>

Could Rvsnprintf (in src/main/errors.c) be added to the R API
with prototype in include/R_ext/Print.h say?

Here's my problem.  I'm trying to write some code that is not
totally tied to R.  Hence I want R style error messaging to
be isolated in a small module.  I do not want #include <R.h>
and calls to error (Rf_error) in most of my code.
Hence I want to write a module with something like

----- begin code snippet -----
#include <stdarg.h>
#include <stdio.h>
#include <R.h>

#define BUFSIZE 1024

void die(const char *format, ...)
{
    char buf[BUFSIZE];
    va_list arg;

    va_start(arg, format);
    vsnprintf(buf, BUFSIZE, format, arg);
    va_end(arg);
    buf[BUFSIZE - 1] = '\0';
    error(buf);
}
----- end code snippet -----

But that's not portable because vsnprintf isn't.
You've already made a big effort to work around nonportability of
vsnprintf, but don't make it available in the API.  Why not?

If I could change vsnprintf to Rvsnprintf above, then I wouldn't
have to do some horrible autoconf song and dance that probably wouldn't
be completely portable anyway.

Or is there a better solution I haven't seen?

-- 
Charles Geyer
Professor, School of Statistics
University of Minnesota
charlie@stat.umn.edu


[Rd] add Rvsnprintf to API ??
Charles Geyer