Dear R-users, I have written a short VB application to clean and format my R code. Everything works fine except one small issue that I did not expected; it is related the automatic replacement of assignment signs from "=" to "<-". Most functions or arguments seem to accept either = or <-, but some don't (e.g. ls(all=TRUE)). The result is that my supposedly clean codes do not run anymore :-( Is there a way to know the list of arguments/functions that do not accept "<-" signs ? Thanks in advance. Sebastien
No function accepts <- in place of =. In the first of the 4 examples below we are simply setting variable b to 10 and then passing it to f as its first argument. f(b = 10) would be different since that specifies that we want argument b to take on the value of 10. f <- function(a=1, b=2) a-b # these 5 lines below all give the same result # except the first 3 also have the side effect # of creating a variable b f(b <- 10) b <- 10; f(b) f(a = b <- 10) f(10) f(a=10) On Mon, Jun 2, 2008 at 10:05 AM, S?bastien <pomchip at free.fr> wrote:> Dear R-users, > > I have written a short VB application to clean and format my R code. > Everything works fine except one small issue that I did not expected; it is > related the automatic replacement of assignment signs from "=" to "<-". Most > functions or arguments seem to accept either = or <-, but some don't (e.g. > ls(all=TRUE)). The result is that my supposedly clean codes do not run > anymore :-( > Is there a way to know the list of arguments/functions that do not accept > "<-" signs ? > > Thanks in advance. > > Sebastien > > ______________________________________________ > 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. >
S?bastien wrote:> Dear R-users, > > I have written a short VB application to clean and format my R code. > Everything works fine except one small issue that I did not expected; it > is related the automatic replacement of assignment signs from "=" to > "<-". Most functions or arguments seem to accept either = or <-, but > some don't (e.g. ls(all=TRUE)). The result is that my supposedly clean > codes do not run anymore :-( > Is there a way to know the list of arguments/functions that do not > accept "<-" signs ?You are surely mixing two concepts here. When you are doing an assignment of a value to a variable, you may use either <- or =. Example a <- 2 a = 2 both bind the value of 2 to the symbol "a". When you call a function, for example ls, you can specify the argument names, such as ls(all = TRUE). If you attempted ls(all <- TRUE), the value of TRUE will be assigned to the symbol 'all', and then ls will be evaluated with its first argument "names" as TRUE, which produces your error. You almost certainly want ls(all = TRUE). After the error, try typing 'all' at the R prompt. The 'all' function definition has now been overwritten and is simply TRUE, which you probably do not want either. So, there really is no concept of whether or not a function "accepts <- signs". You want to use = in your function calls, since the '<-' method is actually assigning values. Hope that helps, Erik> > Thanks in advance. > > Sebastien > > ______________________________________________ > 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.