Levent TERLEMEZ
2011-Oct-31 13:30 UTC
[R] assignment operator <- does not work in a function...
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:>kuralfonkfunction() { 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. Michael Weylandt
2011-Oct-31 15:41 UTC
[R] assignment operator <- does not work in a function...
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. >
Mehmet Suzen
2011-Oct-31 16:22 UTC
[R] assignment operator <- does not work in a function...
Are you running the function with Rscript or R CMD? If yes, try it interactively. Or, try to run them separate functions.>-----Original Message----- >From: r-help-bounces at r-project.org[mailto:r-help-bounces at r-project.org]>On Behalf Of Levent TERLEMEZ >Sent: 31 October 2011 13:31 >To: r-help at r-project.org >Subject: [R] assignment operator <- does not work in a function... > >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 arulseVizpackages:> >>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.LEGAL NOTICE This message is intended for the use o...{{dropped:10}}