[R] regex challenge

Frank Harrell f.harrell at Vanderbilt.Edu
Thu Aug 15 05:13:39 CEST 2013


I would like to be able to use gsub or gsubfn to process a formula and 
to translate the variables but to ignore expressions in the formula. 
Supposing that the R formula has already been transformed into a 
character string and that the transformation is to convert variable 
names to upper case and to append z to the names, an example would be to 
convert y1 + y2 ~ a*(b + c) + d + f * (h == 3) + (sex == 'male')*i to 
Y1z + Y2z ~ Az*(Bz + Cz) + Dz + Fz * (h == 3) + (sex == 'male')*Iz.  Any 
expression that is not just a simple variable name would be left alone.

Does anyone want to try their hand at creating a regex that would 
accomplish this?

Thanks
Frank
-- 
Frank E Harrell Jr Professor and Chairman      School of Medicine
                    Department of Biostatistics Vanderbilt University



More information about the R-help mailing list