Assigning an abject to a list within the function


I want to write a function in R which assigns a new object to a list item.

I have:

RM_and_CM_list                   <- vector(mode='list', length=2)
names(RM_and_CM_list)  <- c('RM', 'CM')
GLM_Frequency <- 1

Set_RM_and_CM <- function(model){
  if (!is.null(RM_and_CM_list[["CM"]])){
    RM_and_CM_list[["RM"]] <- RM_and_CM_list[["CM"]] 
    RM_and_CM_list[["CM"]] <- model
  if (is.null(RM_and_CM_list[["CM"]])){ 
    RM_and_CM_list[["CM"]] <- model

Set_RM_and_CM(model = GLM_Frequency)

My last line calls the functions. It should assign a GLM_Frequency object to a an item of the list. However it doesnt. If the same thing is written outside function, it works.

I cant understand why my function doesnt work. Anyone can help?

p.s. Anyone knows a good source for functional writing in R?

Sorry, i find it hard to understand what does remote library have something to with lists

My bad, i got my post responses mixed up

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.