We can use append
function to add element to list. For example like blow.
a_list <- list()
a_list <- append(a_list, "a")
But I want do to like this. The append_new
don't return but change the a_list.
a_list <- list()
append_new(a_list, "a")
It can be used by eval
function to do this.
a_list <- list()
eval(parse(text="a_list[[1]]<-a"))
a_list
But if I want to write the function add_element_to_list
.
a_list <- list()
add_element_to_list(a_list, "a")
a_list ## same as list("a")
How to write the function? This function like assign
but more powerful.
The post use eval(parse(text=""))
but it can not write in the custom function append_new
.