[R] rpanel / list error
R. Michael Weylandt
michael.weylandt at gmail.com
Mon Mar 12 20:50:41 CET 2012
My code doesn't give that error so you must have done something
differently -- without seeing your code, I can't tell you what though.
Also, please cc the list on follow-up if you are seeking further help.
I'm not particularly knowledgeable about rpanel and others might be
able to give concrete help.
Michael
On Sun, Mar 11, 2012 at 9:42 AM, James Carey <james.jism.carey at gmail.com> wrote:
> I have made the changes recommended but now I am getting the following
> error:
>
> Error in index > 100 :
> comparison (6) is possible only for atomic and list types
>
> I have an if statement in the body of the while() to only calculate the
> values once 100 steps have been passed so I am guessing this is the cause of
> this error.
>
> On Sun, Mar 11, 2012 at 1:57 AM, R. Michael Weylandt
> <michael.weylandt at gmail.com> wrote:
>>
>> Your immediate problem seems to be that you use "sum" as a variable
>> name when it is also a function name. You also have scoping issues
>> that result from how you're using with() -- if you don't return an
>> object, it gets thrown away after the with() function is done (part of
>> the functional paradigm) -- I've started to clean this up a little,
>> but it now bumps up against the fact you don't return things in the
>> rpanel bits -- I don't really use that package much but hopefully this
>> gets you going in the right way:
>>
>> main <- function(panel) {
>> SUM <- with(panel,{
>> LAST = 1100
>> START = 0
>> INDX = 0 #### Starting Conditions
>> revenue = 0
>> minStock = panel$minStock
>> maxStock = 100
>> inventory = 100
>> order_costs = 0
>> storage_costs = 0
>> orderlevel = k
>> SUM = list(ninventory = inventory,
>> order_costs = 0,
>> storage_costs = 0,
>> revenue = 0,
>> index = INDX)
>> # initial list containing values
>>
>> while(SUM$index < LAST && inventory >0) {
>> SUM$order_costs = SUM$order_costs + order_costs
>> SUM$storage_costs = SUM$storage_costs + storage_costs
>> SUM$ninventory = SUM$ninvenotry + inventory
>>
>> SUM$index = SUM$index + 1
>> }
>> SUM
>> })
>> print(SUM)
>> sis = list(Time = SUM$index,
>> StorageCosts=SUM$storage_costs,
>> OrderCosts = SUM$order_cost,
>> fInventory = SUM$ninventory)
>> print(sis)
>> return(sis)
>> }
>>
>> panel <- rp.control(title="Stochastic Case")
>> rp.button(panel,action=main,title="Calculate")
>> rp.slider(panel,k,from=10,to=90,resolution=10,showvalue=TRUE,title="Select
>> Order Size",initval=70)
>> rp.slider(panel,minStock,from=10,to=90,resolution=10,initval=
>> 50,title="Minimum Stock Level",showvalue=TRUE)
>>
>>
>> Note also that "index" is a function so you need to be smart in how
>> you use that name.
>>
>> Michael
>>
>> On Fri, Mar 9, 2012 at 6:59 AM, jism7690 <james.jism.carey at gmail.com>
>> wrote:
>> > Hi Michael,
>> >
>> > Thank you for your reply. I have uploaded the minimum, I have left out
>> > the
>> > formulas for calculating the amounts as they are not important to the
>> > loop.
>> > Basically I have a while loop running that adds to the list of values
>> > and
>> > then outside this loop I have a list called sis, this is the list that
>> > is
>> > causing the error. I would like this list to return the values with
>> > panel,
>> > before I used rpanel it was returning values perfectly.
>> >
>> > Thanks
>> >
>> > main <- function(panel)
>> > {
>> > with(panel,{
>> >
>> > LAST = 1100
>> > START = 0
>> > index = 0 #### Starting Conditions
>> > revenue = 0
>> > minStock = panel$minStock
>> > maxStock = 100
>> > inventory = 100
>> > order_costs = 0
>> > storage_costs = 0
>> > orderlevel =panel$k
>> > sum =
>> > list(ninventory=inventory,order_costs=0,storage_costs=0,revenue = 0)
>> > # initial list containing values
>> >
>> > while(index < LAST && inventory >0) {
>> >
>> > sum$order_costs = sum$order_costs + order_costs
>> > sum$storage_costs = sum$storage_costs + storage_costs
>> > sum$ninventory = sum$ninvenotry + inventory
>> >
>> >
>> > index = index + 1
>> >
>> > }
>> > })
>> > sis = list(Time =
>> > index,StorageCosts=sum$storage_costs,OrderCosts=
>> > sum$order_cost,fInventory = sum$ninventory)
>> > return(sis)
>> > }
>> >
>> >
>> > panel <- rp.control(title="Stochastic Case", size=panel.size)
>> > rp.button(panel,action=main,title="Calculate",pos=pos.go.button)
>> >
>> > rp.slider(panel,k,from=10,to=90,resolution=10,showvalue=TRUE,title="Select
>> > Order Size",pos=pos.order.slider,initval=70)
>> >
>> > rp.slider(panel,minStock,from=10,to=90,resolution=10,pos=pos.minstock.slider,initval
>> > = 50,title="Minimum Stock Level",showvalue=TRUE)
>> >
>> >
>> >
>> > --
>> > View this message in context:
>> > http://r.789695.n4.nabble.com/rpanel-list-error-tp4457308p4459254.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