[R] external variable by inside-function routines modifications

baptiste auguie baptiste.auguie at googlemail.com
Thu Oct 8 19:22:49 CEST 2009


Hi,

with assign,

foo <- function(var){
  assign("var", var+1, envir = .GlobalEnv)
}

var =1
foo(2)
var
# [1] 3

HTH,

baptiste



2009/10/8 devol <sunduck at gmail.com>:
>
> Dear all,
>
>  could you please advice whether it is possible somehow to modify an
> external (from the point of some function view) variable by some
> function-internal operators. For example
>
>> var=1
>> foo<-function(var){var=var+1}
>> foo(var)
>> var
> [1] 1
>
> but the goal is to get the var equal to 2 in this specific case.
>
> Thanks!
> --
> View this message in context: http://www.nabble.com/external-variable-by-inside-function-routines-modifications-tp25803308p25803308.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>




More information about the R-help mailing list