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

From: Wacek Kusnierczyk <Waclaw.Marcin.Kusnierczyk_at_idi.ntnu.no>
Date: Thu, 12 Feb 2009 11:07:23 +0100


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

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


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

Received on Thu 12 Feb 2009 - 09:15:19 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 12 Feb 2009 - 09:30:21 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive