0

I am trying to combine a variable date with a piece of text so that it looks as follows:

time <- c(end_date_override="20180531")

This is my code:

bb <- Sys.Date()-1
b1 <- paste("c(end_date_override","",sep = "=")
b1<-noquote(b1)
b2 <- as.character(bb)
b3 <- paste(b1,b2)

This does not give a result in the format c(end_date_override="20180531")

I would appreciate your advice.

Thanks in advance.

s__
  • 9,270
  • 3
  • 27
  • 45
asathe1
  • 31
  • 4
  • What is your expected return? A named character as time is as you defined it. Or if you want a text returned that includes the data in bb? – phiver Jun 29 '18 at 15:12
  • A named character as time is as I have defined it please? – asathe1 Jun 29 '18 at 15:20
  • I want it to take the date applied to bb and create a named char such as this:- c(end_date_override="20180627") – asathe1 Jun 29 '18 at 15:21

2 Answers2

1

What about:

bb <- format(Sys.Date()-1,'%Y%m%d')
b1 <- paste("c(end_date_override=",bb,")", sep='"')
b1 <- noquote(b1)
b1  
[1] c(end_date_override="20180628")
s__
  • 9,270
  • 3
  • 27
  • 45
0

To get a named character as time you can use the following code. The first line is what you need. The others are showing the outcome.

b3 <- setNames(as.character(Sys.Date()-1), "end_date_override")

b3
end_date_override 
     "2018-06-28" 

str(b3)
 Named chr "2018-06-28"
 - attr(*, "names")= chr "end_date_override"
phiver
  • 23,048
  • 14
  • 44
  • 56