Re: [Rd] R readline not honoring RCustomCompletion

2010-08-12 Thread Prof Brian Ripley
And where did you find the documentation that it should?  Not in the R 
sources AFAICS 


The readline documentation suggests that applications should set their 
name by rl_readline_name.  That will be done and documented as from R 
2.12.0, but the application name is 'R', not 'RCustomCompletion' -- 
and the only example in any of the postings you cite is nothing to do 
with completion.


On Mon, 9 Aug 2010, Rafael Laboissiere wrote:


This issue has been brought at least twice in R-help:


Which was of course the wrong list.


https://stat.ethz.ch/pipermail/r-help/2008-September/173828.html
https://stat.ethz.ch/pipermail/r-help/2009-May/197360.html

Looking at the source in src/unix/sys-std.c, it seems that the definition
of rl_readline_name as "RCustomCompletion" is made after the readline
library has been initialized and the ~/.inputrc file has been read.
Typing "C-x C-r" at the R prompt makes the definitions under "$if
RCustomCompletion" work, but this is not what one expects the R users to
do.

Attached below is the trivial patch that seems to fix the problem.

Best regards,

Rafael Laboissiere



--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] R readline not honoring RCustomCompletion

2010-08-12 Thread Rafael Laboissiere
* Prof Brian Ripley  [2010-08-12 09:04]:

> The readline documentation suggests that applications should set
> their name by rl_readline_name.  That will be done and documented as
> from R 2.12.0, but the application name is 'R', not
> 'RCustomCompletion' -- and the only example in any of the postings
> you cite is nothing to do with completion.

I have seen your changes in the SVN repository.  Thank you for making
this improvement in R.

Best regards,

Rafael

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] c.POSIXct

2010-08-12 Thread Gabor Grothendieck
Currently if x1 and x2 are POSIXct then c(x1, x2) will not have a
tzone attribute even if x1 or x2 or both do but it should.

This could be fixed with the following c.POSIXct:

c.POSIXct <- function (..., recursive = FALSE) {
tzones <- lapply(list(...), attr, which = "tzone")
lengths <- sapply(tzones, length)
if (any(lengths > 1)) stop("tzone cannot have length greater than 1")
which <- sapply(tzones, length) == 1
tzone <- unique(unlist(tzones[which]))
if (length(tzone) != 1) tzone <- NULL
structure(c(unlist(lapply(list(...), unclass))), class = c("POSIXt",
"POSIXct"), tzone = tzone)
}

# test
x1 <- Sys.time()
x2 <- structure(x1, tzone = "UTC")
x3 <- structure(x1, tzone = "other")

# these all currently give NULL but with
# above give indicated value

attr(c(x1, x1), "tzone") # NULL
attr(c(x2, x2), "tzone") # "UTC"
attr(c(x1, x2), "tzone") # "UTC"
attr(c(x2, x1), "tzone") # "UTC"
attr(c(x1, x2, x3), "tzone") # NULL

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] readline operate-and-get-next

2010-08-12 Thread Prof Brian Ripley

On Sun, 8 Aug 2010, Rafael Laboissiere wrote:


Okay, I could not refrain myself and implemented the change in
src/unix/sys-std.c.  The patch is attached below.  I tested it in the
2.11.1 source and it worked fine.  At any rate, the patch applies cleanly
to the SVN source.

Three notes about this patch:

1. The code is taken from the bash source (bashline.c) with minimal
  changes.


Hmm, one of those 'minimal changes' was to omit the copyright and 
licence statements.  I very much doubt that you have the right to post 
copied code without those, and we certainly do not have the right to 
use such code in the R sources.


Bash is currently distributed under a licence that FSF deems 
incompatible with that of R, and we would only accept code which can 
be (re-)licensed under GPL (>=2).  So it is critical where exactly you 
copied this from.


We can only consider code contributions where the provenance and 
licensing of the code is clearcut.  That includes your own 
contributions, and since you posted from an address which is likely to 
be your employer, who owns the copyright of your work needs to be 
clear too.


If you provide a patch with these extremely important issues resolved, 
we will consider its merits.  But not otherwise.




2. The changes are put inside #ifdef HAVE_READLINE_HISTORY_H, because
  it uses history related functions.

3. In the call to rl_add_defun, the operate-and-get-next function is
  bound to C-o.  This is not the behavior of Bash and Octave, which
  depends on the user to define the key binding in ~/.inputrc.  To
  mimic this behavior, the code should be rather:

  rl_add_defun ("operate-and-get-next", operate_and_get_next, -1);


Best regards,

Rafael Laboissiere

* Rafael Laboissiere  [2010-08-07 13:07]:


Both Bash and Octave have a nifty addition to the readline library called
"operate-and-get-next", bound to "C-o".  This function accepts the
current line for execution and fetch the next line relative to the
current line from the history for editing (see
http://www.faqs.org/docs/bashman/bashref_101.html).

This feature has a huge impact in my productivity using Bash and Octave
interactively, since it avoids those numerous arrow key strokes in order
to rerun a previous block of commands.

I looked at the Bash sources and it does not seem too complicate to
implement.  Octave has borrowed practically the same code from Bash.
Before I start looking at the R code, I would like to know whether the R
developers had already planned to include the operate-and-get-next
feature into R.

Best regards,

Rafael Laboissiere




--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] accessing tcl variables within R and tcl

2010-08-12 Thread Adrian Waddell
Dear R users,

I have some troubles with dealing with tclObj objects. I try to explain
it with a toy example:

Say I define the following tcl procedure which just prints out each list
element

library(tcltk)
.Tcl('proc test {myList} {
foreach i $myList {
  puts stdout  $i
}
}')

and I call it with:

> tcl('test',letters[1:5])# Works as expected

Now say I define a tcl variable first:

> a <- tclVar("")
> tclObj(a) <- as.tclObj(letters[1:5])

> tcl('set',a)  # output list

However

> tcl('test',a) # does not work as expected, returns the variable name

Why not? In fact, how do get the name of the "a" list in tcl (something
like RTcl...) so I could use it as follows
> .Tcl('test $RTcl1') #works

Loops are much quicker in tcl than in R, hence I try to do some
computations in tcl and not via wrapper function in R. I therefore need
a way to easily access tcl variables from within R and tcl.

Thanks for any help,

Adrian Waddell

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] readline operate-and-get-next

2010-08-12 Thread Rafael Laboissiere
* Prof Brian Ripley  [2010-08-12 18:25]:

> Hmm, one of those 'minimal changes' was to omit the copyright and
> licence statements.  I very much doubt that you have the right to post
> copied code without those, and we certainly do not have the right to
> use such code in the R sources.

I am sorry for this omission.

> Bash is currently distributed under a licence that FSF deems
> incompatible with that of R, and we would only accept code which can
> be (re-)licensed under GPL (>=2).  So it is critical where exactly
> you copied this from.
> 
> We can only consider code contributions where the provenance and
> licensing of the code is clearcut.

The code was taken from file bashline.c distributed in the bash-3.0
sources (available from ftp://ftp.gnu.org/gnu/bash/bash-3.0.tar.gz).
The header of this file is:

/* bashline.c -- Bash's interface to the readline library. */

/* Copyright (C) 1987-2004 Free Software Foundation, Inc.

   This file is part of GNU Bash, the Bourne Again SHell.

   Bash is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   Bash is distributed in the hope that it will be useful, but WITHOUT
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
   License for more details.

   You should have received a copy of the GNU General Public License
   along with Bash; see the file COPYING.  If not, write to the Free
   Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */

Would that be okay?

> That includes your own contributions, and since you posted from an
> address which is likely to be your employer, who owns the copyright of
> your work needs to be clear too.

Well, in the proposed patch there was no line of code that could 
genuinely be called "mine".  I think that my contribution would fall
below the "legally significant" threshold, as defined by the GNU project:

http://www.gnu.org/prep/maintain/maintain.html#Legally-Significant

I would classify my changes as mere "ideas", as discussed in the URL
above (besides the fact that the code does actually work).  In this case,
I do not think we should bother making me hold copyright on the sys-std.c
file.

> If you provide a patch with these extremely important issues
> resolved, we will consider its merits.  But not otherwise.

Please, tell me whether what I wrote above is okay and I will prepare a
new patch containing the copyright clarification.

Best regards,

Rafael Laboissiere

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] accessing tcl variables within R and tcl

2010-08-12 Thread Gabor Grothendieck
On Thu, Aug 12, 2010 at 2:14 PM, Adrian Waddell  wrote:
> Dear R users,
>
> I have some troubles with dealing with tclObj objects. I try to explain
> it with a toy example:
>
> Say I define the following tcl procedure which just prints out each list
> element
>
> library(tcltk)
> .Tcl('proc test {myList} {
>    foreach i $myList {
>      puts stdout  $i
>    }
> }')
>
> and I call it with:
>
>> tcl('test',letters[1:5])    # Works as expected
>
> Now say I define a tcl variable first:
>
>> a <- tclVar("")
>> tclObj(a) <- as.tclObj(letters[1:5])
>
>> tcl('set',a)  # output list
>
> However
>
>> tcl('test',a) # does not work as expected, returns the variable name
>
> Why not? In fact, how do get the name of the "a" list in tcl (something
> like RTcl...) so I could use it as follows
>> .Tcl('test $RTcl1') #works
>
> Loops are much quicker in tcl than in R, hence I try to do some
> computations in tcl and not via wrapper function in R. I therefore need
> a way to easily access tcl variables from within R and tcl.
>

Try this:

tcl("test", tclvalue(a))

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] accessing tcl variables within R and tcl

2010-08-12 Thread Peter Dalgaard
Adrian Waddell wrote:
> Dear R users,
> 
> I have some troubles with dealing with tclObj objects. I try to explain
> it with a toy example:
> 
> Say I define the following tcl procedure which just prints out each list
> element
> 
> library(tcltk)
> .Tcl('proc test {myList} {
> foreach i $myList {
>   puts stdout  $i
> }
> }')
> 
> and I call it with:
> 
>> tcl('test',letters[1:5])# Works as expected
> 
> Now say I define a tcl variable first:
> 
>> a <- tclVar("")
>> tclObj(a) <- as.tclObj(letters[1:5])
> 
>> tcl('set',a)  # output list
> 
> However
> 
>> tcl('test',a) # does not work as expected, returns the variable name
> 
> Why not? In fact, how do get the name of the "a" list in tcl (something
> like RTcl...) so I could use it as follows
>> .Tcl('test $RTcl1') #works
> 
> Loops are much quicker in tcl than in R, hence I try to do some
> computations in tcl and not via wrapper function in R. I therefore need
> a way to easily access tcl variables from within R and tcl.
> 
> Thanks for any help,

Ow, that's been a while... However

tcl('test', tclvalue(a))

seems to do the trick, as does

tcl('test', tclObj(a))

The latter presumably being preferable, since it avoids conversion to
and from an R object.

If I remember these matters correctly, you are seeing the difference
between "set RTcl1" and "test $RTcl1".

-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel