Closed khughitt closed 11 years ago
Thanks so much for your suggestion. However, I'm concerned that your code would turn a command like this...
sample(x=1:6, size=10, replace=TRUE)
...into this...
sample(x <- 1:6, size <- 10, replace <- TRUE)
I'm sure we can find a way to get around this. Any suggestions?
Thanks, Nick
Whoops! Good catch -- I hadn't gotten that far into the tutorial yet and completely neglected that.
I updated the regex to only adjust equal signs near the beginning of the string. What do you think?
Alternatively, it would probably also be safe to convert all arrow assignment operators to equal signs since I believe that should work in all cases.
Okay, I think it should work this time...
> str.ans = 'foo.bar = sample(x=1:6, size=10)'
> sub('^ *([\\w\\d\\.]*) *(=|<-) *', '\\1 <- ', str.ans, perl=TRUE)
[1] "foo.bar <- sample(x=1:6, size=10)"
> str.ans = 'fooBar2 <- sample(x=1:6, size=10)'
> sub('^ *([\\w\\d\\.]*) *(=|<-) *', '\\1 <- ', str.ans, perl=TRUE)
[1] "fooBar2 <- sample(x=1:6, size=10)"
> str.ans = 'foo_bar_2=sample(x=1:6, size=10)'
> sub('^ *([\\w\\d\\.]*) *(=|<-) *', '\\1 <- ', str.ans, perl=TRUE)
[1] "foo_bar_2 <- sample(x=1:6, size=10)"
It should catch all variable assignment operations on the left side. What it will not catch are things like "x[x < 5] = 0". Another regex could be used to catch those cases as well though if you think it will come up in tutorials.
Great, thanks. I'll play with it this week and most likely implement, as I've heard the same request from others (i.e. desire to use '=' instead of '<-' for assignments). I really appreciate your help on this.
Sincerely, Nick
On Mon, Sep 30, 2013 at 6:29 AM, Keith Hughitt notifications@github.comwrote:
Okay, I think it should work this time...
str.ans = 'foo.bar = sample(x=1:6, size=10)' sub('^ ([\w\d.]) (=|<-) ', '\1 <- ', str.ans, perl=TRUE) [1] "foo.bar <- sample(x=1:6, size=10)" str.ans = 'fooBar2 <- sample(x=1:6, size=10)' sub('^ ([\w\d.]) _(=|<-) ', '\1 <- ', str.ans, perl=TRUE) [1] "fooBar2 <- sample(x=1:6, size=10)" str.ans = 'foo_bar_2=sample(x=1:6, size=10)' sub('^ ([\w\d.]_) (=|<-) ', '\1 <- ', str.ans, perl=TRUE) [1] "foo_bar_2 <- sample(x=1:6, size=10)"
It should catch all variable assignment operations on the left side. What it will not catch are things like "x[x < 5] = 0". Another regex could be used to catch those cases as well though if you think it will come up in tutorials.
— Reply to this email directly or view it on GitHubhttps://github.com/ncarchedi/swirl/pull/3#issuecomment-25350688 .
Nicholas A. Carchedi ScM Student, Biostatistics Johns Hopkins Bloomberg School of Public Health 301.802.0573 | nick.carchedi@gmail.com
Your code has been merged. Thank you again for your help on this. I have been swamped the past few days and haven't had a chance to address it.
Sincerely, Nick
No problem! I'm glad I was able to contribute a little bit.
Please continue to do so as the project progresses. Mind minds > Few minds.
On Wed, Oct 2, 2013 at 7:04 AM, Keith Hughitt notifications@github.comwrote:
No problem! I'm glad I was able to contribute a little bit.
— Reply to this email directly or view it on GitHubhttps://github.com/ncarchedi/swirl/pull/3#issuecomment-25530425 .
Nicholas A. Carchedi ScM Student, Biostatistics Johns Hopkins Bloomberg School of Public Health 301.802.0573 | nick.carchedi@gmail.com
Hello,
Here is a small patch to allow for command answers that use "var = x" syntax instead of "var <- x" and allowing for variable white-space on either side of the assignment operator. The rest of the changes to the file are just auto-stripping of white-space from my .vimrc (sorry!)
Very cool project, by the way. Keep up the good work!