[R] assignment operator <- does not work in a function...

R. Michael Weylandt michael.weylandt at gmail.com
Mon Oct 31 16:41:35 CET 2011


It's a matter of environments:

your function makes "veri" for purposes of the function but then
throws it away when the function is done. If you want it to be
accessible you need to assign it to the global environment with
something like

assign("veri", read.transactions("c:/RVerileri/BitirmeVeri.csv",sep=";",col=1)
, envir = .GlobalEnv)

Michael

On Mon, Oct 31, 2011 at 9:30 AM, Levent TERLEMEZ
<lterlemez at anadolu.edu.tr> wrote:
> Dear Users,
>
> I have a little problem with assignment operator. It's working from command prompt but does not work same as in the command prompt in the function. Am I missing or forgetting something? The function is (tried on both 2.13.1 and 2.13.2) as below using arules and arulseViz packages:
>
>>kuralfonk
> function()
> {
>        require(arules)
>        require(arulesViz)
>        veri<-read.transactions("c:/RVerileri/BitirmeVeri.csv",sep=";",col=1)   #This statement does not add "veri" object to working area
>        #itemFrequencyPlot(veri,type="absolute")
>        #bringToTop(-1)
>        summary(veri) #But this statement gives the right answer
>        itemFrequency(veri,type="absolute") #And this statement does nothing, even the graph window does not open.
> }
>
> Thanks for your tips and corrections,
> Levent.
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> 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