Dear all, I have several datasets and I want to generate pdf plots from them. I also want to generate automatically the names of the files. They are country-specific and the element mycurrentdata[1,1] contains this information. So what I do is something like this: pdf(file=paste(mycurrentdata[1,1], ".pdf", sep=""), width=...etc) The only problem I have is that some of the country names contain white space (e.g., "United Kingdom"). This is no problem for generating the pdf plots but it may become problematic during further processing (e.g. incl. the plots in LaTeX documents). Is there an easy function to strip white space out of character strings (similar to the strip.white=TRUE option in read.table/scan)? I'd appreciate any kind of help and I hope I did not miss anything completely obvious. Thanks, Roland
Maybe another basic question but... Is is possible to accomodate more than a single (independent, not resulting from arranjment of layout=c()) lattice graph in a single win.graph() device? Thanks in advance, PS Maybe duplicated Paulo ________________________________ De: r-help-bounces@r-project.org em nome de Roland Rau Enviada: qua 14-05-2008 17:06 Para: 'r-help@stat.math.ethz.ch' Assunto: [R] strip white in character strings Dear all, I have several datasets and I want to generate pdf plots from them. I also want to generate automatically the names of the files. They are country-specific and the element mycurrentdata[1,1] contains this information. So what I do is something like this: pdf(file=paste(mycurrentdata[1,1], ".pdf", sep=""), width=...etc) The only problem I have is that some of the country names contain white space (e.g., "United Kingdom"). This is no problem for generating the pdf plots but it may become problematic during further processing (e.g. incl. the plots in LaTeX documents). Is there an easy function to strip white space out of character strings (similar to the strip.white=TRUE option in read.table/scan)? I'd appreciate any kind of help and I hope I did not miss anything completely obvious. Thanks, Roland ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]]
> Date: Wed, 14 May 2008 12:06:39 -0400 > From: roland.rproject at gmail.com > To: r-help at stat.math.ethz.ch > Subject: [R] strip white in character strings > > Dear all, > > I have several datasets and I want to generate pdf plots from them. > I also want to generate automatically the names of the files. They are > country-specific and the element mycurrentdata[1,1] contains this > information. > > So what I do is something like this: > pdf(file=paste(mycurrentdata[1,1], ".pdf", sep=""), width=...etc) > > The only problem I have is that some of the country names contain white > space (e.g., "United Kingdom"). This is no problem for generating the > pdf plots but it may become problematic during further processing (e.g. > incl. the plots in LaTeX documents). > > Is there an easy function to strip white space out of character strings > (similar to the strip.white=TRUE option in read.table/scan)?How about> a = " United Kingdom " > paste(unlist(strsplit(a,split=" ")), collapse="")[1] "UnitedKingdom" Note better might is using generic trimming functions after the split to catch any left over non-space white space stuff in each split.> > I'd appreciate any kind of help and I hope I did not miss anything > completely obvious. > > Thanks, > Roland > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code._________________________________________________________________ 1.
It depends on what you mean by striping the white space. Here is an example of how it might be done:> x <- c("United Kingdom", "Europe", "United States", "alonger string")> gsub(" +", "_", x)[1] "United_Kingdom" "Europe" "United_States" "a_longer_string">On Wed, May 14, 2008 at 12:06 PM, Roland Rau <roland.rproject@gmail.com> wrote:> Dear all, > > I have several datasets and I want to generate pdf plots from them. > I also want to generate automatically the names of the files. They are > country-specific and the element mycurrentdata[1,1] contains this > information. > > So what I do is something like this: > pdf(file=paste(mycurrentdata[1,1], ".pdf", sep=""), width=...etc) > > The only problem I have is that some of the country names contain white > space (e.g., "United Kingdom"). This is no problem for generating the pdf > plots but it may become problematic during further processing (e.g. incl. > the plots in LaTeX documents). > > Is there an easy function to strip white space out of character strings > (similar to the strip.white=TRUE option in read.table/scan)? > > I'd appreciate any kind of help and I hope I did not miss anything > completely obvious. > > Thanks, > Roland > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? [[alternative HTML version deleted]]