Re: [R] Assigning several lists to variables whose names are contained in other variables

2021-04-10 Thread Rui Barradas
Hello, I believe that the point we are missing is that datatable$column stores the *names* of the graphs, not the graph objects themselves. So in the loop the objects must be retrieved with mget() or get(). First create a reproducible example. library(tidygraph) my_function <-

Re: [R] Assigning several lists to variables whose names are contained in other variables

2021-04-09 Thread Bert Gunter
I freely admit that I do not understand what you mean. But it sounds like you are trying to make things more complicated than necessary. Perhaps this little example may help clarify the issues: > a <- 1; b <- 2; d <- c(3,5) > stuff <- lapply(list(a,b,d),function(x)x^2) > stuff [[1]] [1] 1

Re: [R] Assigning several lists to variables whose names are contained in other variables

2021-04-09 Thread Wolfgang Grond
As I wrote before, I calculate tbl_graph objects, which will be joined afterwards. Not too much, the number of graphs to calculate is in the range between 5 to 20. Further steps are not automated, because they depend on how the single graphs look like, and which of them will be joined. For

Re: [R] Assigning several lists to variables whose names are contained in other variables

2021-04-09 Thread Wolfgang Grond
David, I don't think that this is the case. When I do the calculation like this subnet_MYSUBNET <- my_function(MYSUBNET), i.e. assigning a variable by hand to each function result, all is fine. Am 9. April 2021 17:22:05 MESZ schrieb David Winsemius : > >On 4/9/21 5:21 AM, Wolfgang Grond

Re: [R] Assigning several lists to variables whose names are contained in other variables

2021-04-09 Thread Wolfgang Grond
Folks, first of all - thanks a lot for your hints! I will try each again and think about, why I get error messages. But to resume: if I understand you right: there is no way to do something like this: $name = $result? Regards Wolfgang Am 9. April 2021 15:43:27 MESZ schrieb Rui Barradas :

Re: [R] Assigning several lists to variables whose names are contained in other variables

2021-04-09 Thread David Winsemius
On 4/9/21 5:21 AM, Wolfgang Grond wrote: Greg, here I get the error message: Error my_function(val) : cannot find function my_function. I'm guessing that you are following someone else's blog and have failed one of two things: - understand that what was meant by the author was that you

Re: [R] Assigning several lists to variables whose names are contained in other variables

2021-04-09 Thread Rui Barradas
Hello, my_function seems to be a function you have defined somewhere in your code. In your original post you mention it 3 times, this is the first one: subnet_MYSUBNET <- my_function(MYSUBNET) So Ivan's and Greg's code should work, they use a function you haven't posted but is assumed to

Re: [R] Assigning several lists to variables whose names are contained in other variables

2021-04-09 Thread Wolfgang Grond
Greg, here I get the error message: Error my_function(val) : cannot find function my_function. Am 9. April 2021 12:35:40 MESZ schrieb Greg Minshall : >Wolfgang, > >> result <- assign(paste("subnet_",  val, sep = "") >> >> result <- my_function(val) > >i don't understand why you are twice

Re: [R] Assigning several lists to variables whose names are contained in other variables

2021-04-09 Thread Wolfgang Grond
Ivan, same situation when I try your list() solution: Error in eval ... : object 'function' not found ( I think anything about my_function is meant). Am 9. April 2021 13:43:57 MESZ schrieb Ivan Krylov : >Dear Wolfgang, > >On Fri, 9 Apr 2021 11:48:55 +0200 >Wolfgang Grond wrote: > >> I want

Re: [R] Assigning several lists to variables whose names are contained in other variables

2021-04-09 Thread Wolfgang Grond
Dear Ivan, when I try your solution with lapply as below I get the following error message: Error in eval ... : object 'function' not found ( I think anything about my_function is meant). Am 9. April 2021 13:43:57 MESZ schrieb Ivan Krylov : >Dear Wolfgang, > >On Fri, 9 Apr 2021 11:48:55 +0200

Re: [R] Assigning several lists to variables whose names are contained in other variables

2021-04-09 Thread Ivan Krylov
Dear Wolfgang, On Fri, 9 Apr 2021 11:48:55 +0200 Wolfgang Grond wrote: > I want to assign the subnets to variables whose names contain the > name of the subnet Apologies if this sounds too opinionated, but creating variable names from variable values is a FAQ in a different dynamic language:

Re: [R] Assigning several lists to variables whose names are contained in other variables

2021-04-09 Thread Greg Minshall
Wolfgang, > result <- assign(paste("subnet_",  val, sep = "") > > result <- my_function(val) i don't understand why you are twice assigning to =result=. also, the first assignment doesn't seem well formatted (t's missing a value?). did you mean something like : assign(paste("subnet_",  val,

Re: [R] Assigning several lists to variables whose names are contained in other variables

2021-04-09 Thread PIKAL Petr
) the result variable to my_function result So your overall cycle gives you only one result variable containing last value computed by my_function. Cheers Petr > -Original Message- > From: R-help On Behalf Of Wolfgang Grond > Sent: Friday, April 9, 2021 11:49 AM > To: mailman, r

[R] Assigning several lists to variables whose names are contained in other variables

2021-04-09 Thread Wolfgang Grond
Dear all, I'm creating a list (which is a tbl_graph) by a function, and assign the result to a variable: subnet_MYSUBNET <- my_function(MYSUBNET) # MYSUBNET: a tbl_graph Because there are multiple subnets to create, I can get the names of the subnets (MYSUBNET1, MYSUBNET2, MYSUBNET3, etc.)