Hi, The parser doesn't seem to like this: somePackage::foo(x) <- value somePackage:::foo(x) <- value where foo() is a replacement function or method defined in package somePackage. For example: > x <- integer(4) > base::length(x) <- 7 Error in base::length(x) <- 7 : invalid function in complex assignment I've tried to put some back quotes on the left side of the assignment in different ways but was not successful. So finally I had to use the non-replacement form: > x <- base::`length<-`(x, 7) > x [1] 0 0 0 0 NA NA NA Is there a way to avoid this? Thanks! H.
On Fri, Apr 18, 2008 at 7:17 PM, Herve Pages <hpages@fhcrc.org> wrote:> Hi, > > The parser doesn't seem to like this: > > somePackage::foo(x) <- value > somePackage:::foo(x) <- value > > where foo() is a replacement function or method defined in package > somePackage. > > For example: > > > x <- integer(4) > > base::length(x) <- 7 > Error in base::length(x) <- 7 : invalid function in complex assignment >I don't think this is a problem with the parser per se but rather with the way replacement works in R. It's trying to replace the length function inside the base namespace, which is not supported. You'd need to do this in two steps. "base_len<-" <- base::"length<-" base_len(x) <- 7 But maybe the way you suggest below is better...> I've tried to put some back quotes on the left side of the assignment in > different ways but was not successful. So finally I had to use the > non-replacement form: > > > x <- base::`length<-`(x, 7) > > x > [1] 0 0 0 0 NA NA NA > > Is there a way to avoid this? > > Thanks! > H. > > ______________________________________________ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >[[alternative HTML version deleted]]
On Fri, 18 Apr 2008, Herve Pages wrote:> Hi, > > The parser doesn't seem to like this: > > somePackage::foo(x) <- value > somePackage:::foo(x) <- value > > where foo() is a replacement function or method defined in package > somePackage.But the error message you show is not from the parser, and> parse(text="somePackage:::foo(x) <- value")expression(somePackage:::foo(x) <- value) attr(,"srcfile") <text> does work. The error you show arises is in the evaluator. That's because that is not legal code. :: and ::: are operators, not part of the language per se (although I have proposed changing that). The message comes at a check for a name, and base::length is not a name. It often helps to look error messages up in the sources.> For example: > > > x <- integer(4) > > base::length(x) <- 7 > Error in base::length(x) <- 7 : invalid function in complex assignment > > I've tried to put some back quotes on the left side of the assignment in > different ways but was not successful. So finally I had to use the > non-replacement form: > > > x <- base::`length<-`(x, 7) > > x > [1] 0 0 0 0 NA NA NA > > Is there a way to avoid this? > > Thanks! > H. > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595