[R] Function source: desired characteristics

Jose Claudio Faria joseclaudio.faria at gmail.com
Sat Sep 26 13:24:33 CEST 2009


Hi,

We've been calling the function "source" (package base) from Tinn-R editor to
send files, marked blocks and selections to R interpreter because it avoids a
lot of problems related with input/output synchronization in the Rgui output.

The new RGedit plugin is also using this function in this way.
We (Jakson Aquino and I) are just finishing a new version of a plug in to Vim
(Vim-R-plugin2) which uses also this resource.

So, we would like to propose two small changes in this function:

1. The "max.deparse" parameter could be a global option with 150 as the
   default value.

   Why? It will avoid the need to send this parameter repeatedly, which causes
   visual pollution in the console.

2. A new parameter (for example: "new.line.echo") to allow the user to define
   whether a new blank line between the output and the subsequent input is
   desired when "echo=T".

Example, suppose we have in the editor the three lines below:

a=rnorm(10)
a
sort(a)

and we would like to send it to R interpreter (file, block or selection).

The current output is (using Vim-R-plugin2):
-------------------------------------------
> source('/tmp/.Rsource-jcfaria', echo=TRUE, max.deparse=50)

> a=rnorm(10)

> a
 [1]  0.08648104 -1.74996635  0.61027538  0.42042031 -0.02025884 -0.39891256
 [7] -0.30219635 -0.84476668  1.06341674 -0.12030620

> sort(a)
 [1] -1.74996635 -0.84476668 -0.39891256 -0.30219635 -0.12030620 -0.02025884
 [7]  0.08648104  0.42042031  0.61027538  1.06341674

>


How it could be (desired):
-------------------------
> source('/tmp/.Rsource-jcfaria', echo=TRUE)
> a=rnorm(10)
> a
 [1]  0.08648104 -1.74996635  0.61027538  0.42042031 -0.02025884 -0.39891256
 [7] -0.30219635 -0.84476668  1.06341674 -0.12030620
> sort(a)
 [1] -1.74996635 -0.84476668 -0.39891256 -0.30219635 -0.12030620 -0.02025884
 [7]  0.08648104  0.42042031  0.61027538  1.06341674
>

We think that both "new.line.echo" and "max.deparse" could be both
global options.

max.deparse   = 150 (default)
new.line.echo = FALSE (default)

Why? To get a clearer output!

In this way the args of this function would become:
---------------------------------------------------
function (file, local = FALSE, echo = verbose, print.eval = echo,
    verbose = getOption("verbose"), prompt.echo = getOption("prompt"),
->  max.deparse.length = getOption("max.deparse"),
->  new.line.echo = getOption("new.line.echo"),
    chdir = FALSE, encoding = getOption("encoding"),
    continue.echo = getOption("continue"),
    skip.echo = 0, keep.source = getOption("keep.source"))

The extra "\n" is located at line 142 of the current source function:
cat("\n", dep, if (do.trunc)...

For GUI/Editor developers this changes will allow to send simpler instructions
and to make standard interfaces.

We think a bad ideia to create a custom version of "source" function because
these changes would be of benefit to other people and projects.

Is it possible to create the "new.line.echo" argument and to put it and
"max.deparse" among the global options?

We will appreciate the position of users and the Core Team.

All the best,
-- 
///\\\///\\\///\\\///\\\///\\\///\\\///\\\///\\\
Jose Claudio Faria
Estatistica - prof. Titular
UESC/DCET/Brasil
joseclaudio.faria at gmail.com
///\\\///\\\///\\\///\\\///\\\///\\\///\\\///\\\




More information about the R-help mailing list