[R] rpanel / list error

R. Michael Weylandt michael.weylandt at gmail.com
Sun Mar 11 02:57:01 CET 2012


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