[R] 7 days confusion over lists

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Thu Jul 5 17:33:34 CEST 2012

I think you need to (re)read the posting guide and "An Introduction to R" and try posting again. Some food for thought:

a) You refer to "list files", but this is not a standard term. As the PG says, you need to supply a self-contained example, which would either include internal objects in dput form, or text data in strings read as though from files (e.g. use the "text" argument).

b) You may benefit from using indexing by character strings rather than numeric index to avoid mixups in sequencing.

c) I think "Crop$" is a typo?

d) The claim that "it stops accepting the assigned values" is more likely to be an error on your part than R being arbitrary. I may be going out on a limb here, but be sure you understand that modifications to data within functions are local, and you have to explicitly return changes if you want them to persist after the function returns.
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
Sent from my phone. Please excuse my brevity.

Wageningen-eR <igor.milosavljevic at wur.nl> wrote:

>I am a Masters student and I am working on my thesis modelling
>farms using a program in R.  I have modified the original code and I am
>having some issues with lists that I cannot figure out.
>Originally, I had list file defining lists such as: Param, Crop1,
>Soil, etc.  (ex. Param <- list() ).  Their subsets were listed as
>Crop1$CContent for example and there was quite a few of them.  There is
>run file that gets the list file going in the following code:
>#--Initialising the lists to store variable values
>tmp <- init_lists()
>Param       <- tmp[[1]]
>Crop1       <- tmp[[2]]
>Fert        <- tmp[[3]]
>Meteo       <- tmp[[4]]
>Soil        <- tmp[[5]]
>RainPattern <- tmp[[6]]
>Crop2       <- tmp[[7]]
>Cropres     <- tmp[[8]]
>The problem here is that the lists get confused with each other; that
>elements of Soil appear in Crop2.  In the run file, I changed the order
>the lists (for example Fert <- tmp[[5]] and Crop2 <-tmp[[3]]) and it
>which ones are confused with what; with some lists not being confused
>all.  I cannot find why this is a problem as the tmps are removed at
>the end
>of the command list shown below and each element is clearly defined as
>part of its given list with (list name)$(Sublist maybe)$(specific
>Either way, I changed the original lists to be more specific, for
>Crop$ <- list(
>CContent <- NA,
>NContent <- NA,
>PContent <- NA,
>KContent <- NA,
>K <- list(
>The issue then became that it stops at a certain point accepting the
>assigned values and keeps them as null.  That is, the list contains an
>element that states Crop2$minYieldN <- NA but the value becomes NULL
>when it
>is run.   Also, the list, say Param, contains both:
>[1] NA
>[1] NA
>[1] NA
>[1] NA
>and some of the value names (up to a point)
>[1] 0.001
>[1] 0.25
>[1] 0.2
>[1] 0.6
>Is it perhaps that the list is too long?  Please let me know if
>comes to mind, it would be great help.
>Thank you!
>-Igor Milosavljevic
>Wageningen University and Research Center
>View this message in context:
>Sent from the R help mailing list archive at Nabble.com.
>R-help at r-project.org mailing list
>PLEASE do read the posting guide
>and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list