Re: [R] How define global Variable?

From: Dimitris Rizopoulos <dimitris.rizopoulos_at_med.kuleuven.be>
Date: Tue 29 Nov 2005 - 01:39:26 EST

try

a <- "old"
test <- function () { assign("a", "new", envir = .GlobalEnv) } test()
a

I hope it helps.

Best,
Dimitris



Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium

Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://www.med.kuleuven.be/biostat/
     http://www.student.kuleuven.be/~m0390867/dimitris.htm


> Hello,
>
> I try to define a global variable.
>
> My example:
>
> R> a <- "old"
> R> test <- function () { a <- "new" }
> R> test()
> R> a # shoud be "new"
>
> This doesn't work. I would like to modify the variable "a" in a
> procedure. How can I do that.
>
> Thank you for helping.
>
> Sven Knüppel (Germany-Berlin)
>
>


> ______________________________________________
> R-help@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

Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm



R-help@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 Received on Tue Nov 29 02:08:56 2005

This archive was generated by hypermail 2.1.8 : Tue 29 Nov 2005 - 04:26:14 EST