From edd at debian.org  Mon Aug 24 17:36:27 2009
From: edd at debian.org (Dirk Eddelbuettel)
Date: Mon, 24 Aug 2009 10:36:27 -0500
Subject: [Rd] Package-level access to Rp->R_Quiet ?
In-Reply-To: <19076.53668.327171.363843@ron.nulle.part>
References: <19076.53668.327171.363843@ron.nulle.part>
Message-ID: <19090.45947.517288.391342@ron.nulle.part>


On 13 August 2009 at 21:53, Dirk Eddelbuettel wrote:
| I would like to simulate the effect of the command-line option --quiet from
| user-level scripts and startup code.  From src/main/CommandLineArgs.c I learn
| that Rp->R_Quiet is set, and I see how that is used in main/main.c.
| 
| I would use this from code in Rprofile.site. In other words, I want to be
| silent when --quiet is used (as e.g. by littler or Rscript) but not by R
| itself in normal interactive mode or from ESS.
| 
| But it seems that I cannot get to this variable outside of the main
| interpreter.  Could this symbol be exported?

Apparently one cannot from user-space at the R level. But by poking into the
not-exported-and-susceptible-to-changes R_ext/RStartup.h header, one can. So
here is a quick littler script using Oleg's inline package:

  #!/usr/bin/r

  suppressMessages(library(inline))

  fn <- cfunction(signature(x="integer"),   # can't we have void functions?
                  body="structRstart rp;
                        Rstart Rp = &rp;
                        R_DefParams(Rp);
                        if (Rp->R_Quiet) Rprintf(\"(quiet) Hello, world!\\n\"); 
                        if (!Rp->R_Quiet) Rprintf(\"(not quiet) Hello, world!\\n\"); ",
                  includes="#include <R_ext/RStartup.h>",
                  convention=".C")
  fn(1)

which runs as expected:

  ~/R/misc$ ./inline_Rprintf.r
  (not quiet) Hello, world!
  ~/R/misc$ 

I still see use for a variant of cat() or warning() or something that could
this test from userspace.  If anyone at R Core agrees, I could submit a
modest patch

Dirk

-- 
Three out of two people have difficulties with fractions.



[Rd] Package-level access to Rp->R_Quiet ?
Dirk Eddelbuettel