Re: [R] How to change letters after space into capital letters

From: Barry Rowlingson <>
Date: Mon 11 Apr 2005 - 21:13:41 EST

Wolfram Fischer wrote:
> What is the easiest way to change within vector of strings
> each letter after a space into a capital letter?

This perl code seems to work:

$s1="this is a lower-cased string";
$s1=~s/ ([a-z])/ \u\1/g;
print $s1."\n";


this Is A Lower-cased String

  but sticking it in a gsub in R doesn't work, even with perl=TRUE:

 > s1
[1] "this is a lowercased string"
 > gsub(" ([a-z])"," \\u\\1",s1,perl=TRUE) [1] "this uis ua ulowercased ustrin"

  But ?gsub does warn you that perl REs may vary depending on the phase of the moon and the PCRE lib on your system.

  I've just noticed the missing 'g' on the end. Anyone know where that went?

  Its looking like a bug in the regex processing:

 > gsub(" ([a-z])"," \\1",s1,perl=TRUE) [1] "this is a lowercased strin"

 > gsub(" ([a-z])","     \\1",s1,perl=TRUE)
[1] "this     is     a     lowercased     st"

  Anyway, back on topic:

> My reason to try to do this is to get more readable abbreviations.
> (A suggestion would be to add an option to abbreviate() which changes
> letters after space to uppercase letters before executing the abbreviation
> algorithm.)

  I think this is what's known as 'Camel Case', because the pattern of upper and lower case looks like humps:

Baz mailing list PLEASE do read the posting guide! Received on Mon Apr 11 21:29:36 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:06 EST