Re: [R] space in R

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Tue, 15 May 2007 08:10:13 -0400

  1. Use this gsub:

txt <- " C744=(C627*C177)/100"
gsub("\\b|([^[:alnum:]])", " \\1 ", txt)

and then strsplit or scan as in prior response.

2. If your text consists of valid R expressions then we can use the R parse function can traverse the tree as shown:

txt <- " C744=(C627*C177)/100"
e <- parse(text = txt)
my.print <- function(e) {

	L <- as.list(e)
	if (length(L) == 0) return(invisible())
	if (length(L) == 1) print(L[[1]])
	else sapply(L, my.print)
	return(invisible())

}
my.print(e[[1]])

There is a parser for a portion of R in the Ryacas package you could look at.

On 5/15/07, elyakhlifi mustapha <elyakhlifi_mustapha_at_yahoo.fr> wrote:
> hello,
> can you help me I need to seperate words and symbol in a mathematics formula as follow
>
> C744=(C627*C177)/100
>
> How could I do please?
>
>
> _____________________________________________________________________________
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_stat.math.ethz.ch 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.
>



R-help_at_stat.math.ethz.ch 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. Received on Tue 15 May 2007 - 12:17:11 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 Tue 15 May 2007 - 13:31:35 GMT.

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