1

I am making calls to an API and want to store the resulting list output in a variable I name dynamically with a timestamp as part of the variable name. I have tried assigning the results to a variable with the date in the name, but have not had luck. Thanks for any help you can offer!

list(date = Sys.Date(),
     time = Sys.time(),
     rand = runif(1, min = 0, max = 1)) %>% 
    assign(x = ., value = paste0(Sys.Date(), "_out"))
M. Wood
  • 450
  • 4
  • 13

1 Answers1

2

Perhaps, we need to switch the arguments

list(date = Sys.Date(),
    time = Sys.time(),
    rand = runif(1, min = 0, max = 1)) %>% 
 assign(x = paste0(Sys.Date(), "_out"), value = ., envir = .GlobalEnv)

-checking

`2020-10-31_out`
#$date
#[1] "2020-10-31"

#$time
#[1] "2020-10-31 17:27:13 CDT"

#$rand
#[1] 0.4813982
akrun
  • 874,273
  • 37
  • 540
  • 662
  • 1
    Thanks @akrun ! Yes, this is one of those silly syntax errors. Spending too much time in the tidyverse, and I forgot that the first parameter defined in the function isn't always the one that you probably passed from the previous function call. – M. Wood Nov 03 '20 at 15:51