From Waclaw.Marcin.Kusnierczyk at idi.ntnu.no  Thu Feb 12 11:07:23 2009
From: Waclaw.Marcin.Kusnierczyk at idi.ntnu.no (Wacek Kusnierczyk)
Date: Thu, 12 Feb 2009 11:07:23 +0100
Subject: [Rd] Patch for src/main/character.c,
	systematizing recent fix to do_grep
Message-ID: <4993F4DB.7020907@idi.ntnu.no>

The attached patch provides a modification to the recent fix/improvement
to do_grep already included in the most recent development version.

The original fix added new functionality to the grep function by adding
a new parameter, 'invert'.  In the source code for the underlying
do_grep, the value of the parameter is used to invert the logical
match-no match flag vector ind.  The modification is distributed across
several lines of code.

The patch systematizes the solution by inverting the logical match flag
vector in place, once for each element in the character vector passed to
grep as the argument 'x'.  In the patched version, the invertion appears
just once in the code.

The patch does not modify the functionality of grep in any way.  If the
respective documentation was updated to cover the new functionality
introduced by the original modification, it still applies to the patched
version.

The patch does not solve any immediate problem.  However, due to
replacing the redundantly distributed original modification with a
one-line modofication, the patch is intended to make it easier to
understand, maintain, and further modify the source code.

The patch also renames the variable 'invert' introduced in the original
modification to 'invert_opt', for consistency with how (almost) all
other logical flag parameters in do_grep are named.  This modification
is again functionally transparent and requires no modifications to the
documentation.


The patch was prepared as follows:

svn co https://svn.R-project.org/R/trunk/
cd trunk
tools/rsync-recommended
# modifications made to src/main/character.c
svn diff > do_grep.diff

The patched sources were successfully compiled and tested as follows:

svn revert -R .
patch -p0 < do_grep.diff
./configure
make
make check

Assuming that appropriate tests were prepared for the extended version
of grep as of the original modification, the patched version was
successfully tested.

The patched grep was also tested as follows:

bin/R --no-save -q <<END
x = replicate(10, paste(sample(letters, 10, replace=TRUE), collapse=''))
pattern = paste(sample(letters, 3), collapse='')
matched = grep(pattern=pattern, x=x, invert=FALSE)
unmatched = grep(pattern=pattern, x=x, invert=TRUE)
print(all.equal(1:length(x), sort(c(matched, unmatched))))
print(version)
END

with the output:

[1] TRUE

platform      
i686-pc-linux-gnu                                              
arch          
i686                                                           
os            
linux-gnu                                                      
system         i686,
linux-gnu                                                
status         Under development
(unstable)                                   
major         
2                                                              
minor         
9.0                                                            
year          
2009                                                           
month         
02                                                             
day           
12                                                             
svn rev       
47904                                                          
language      
R                                                              
version.string R version 2.9.0 Under development (unstable) (2009-02-12
r47904)


vQ

-- 
-------------------------------------------------------------------------------
Wacek Kusnierczyk, MD PhD

Email: waku at idi.ntnu.no
Phone: +47 73591875, +47 72574609

Department of Computer and Information Science (IDI)
Faculty of Information Technology, Mathematics and Electrical Engineering (IME)
Norwegian University of Science and Technology (NTNU)
Sem Saelands vei 7, 7491 Trondheim, Norway
Room itv303

Bioinformatics & Gene Regulation Group
Department of Cancer Research and Molecular Medicine (IKM)
Faculty of Medicine (DMF)
Norwegian University of Science and Technology (NTNU)
Laboratory Center, Erling Skjalgsons gt. 1, 7030 Trondheim, Norway
Room 231.05.060

-------------------------------------------------------------------------------

-------------- next part --------------
A non-text attachment was scrubbed...
Name: do_grep.diff
Type: text/x-diff
Size: 2498 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20090212/16229774/attachment.bin>


[Rd] Patch for src/main/character.c, systematizing recent fix to do_grep
Wacek Kusnierczyk