0

I'm trying to create a data frame with a glue package

previous_month<-sum(June_count$Tranx_count)
recent_month<-sum(July_count$tranx_count)
formula =(recent_month-previous_month)/previous_month
formula<-scales::percent(formula)

#creating dataframe
robo<-data.frame(" " = c("last_2_month:","Recent Month:", "% Increase:"),
                 " " = c("previous_month","recent_month","formula"))



#adding variable to the dataframe using glue package   
    robo<-data.frame(" " = c(glue::glue("{last_2_month:}"),glue::glue("{Recent Month:}"), "% Increase:"),
                     " " = c(glue::glue("{previous_month}"),glue::glue("{recent_month}"),
                             glue::glue("{formula}")))

but I'm getting the error below, can anyone help me resolve this error below

h
  <text>:2:0: unexpected end of input
1: last_2_month:
   ^
Yomi.blaze93
  • 401
  • 3
  • 10
  • 1
    Could you provide some ample data, it's difficult to help without being able to recreate the error – jpsmith Mar 11 '22 at 15:49
  • It's been edited thanks – Yomi.blaze93 Mar 11 '22 at 15:55
  • You still haven’t actually provided any sample data. *Please do so*. That being said, your data.frame creation is weird, why would you attempt to use column names that consist of a single space? Just leave that part off. – Konrad Rudolph Mar 13 '22 at 10:14
  • I have shared the sample data frame, check my previous code, and the comment in the code where it states creating a new data frame. – Yomi.blaze93 Mar 13 '22 at 10:17

1 Answers1

0

I was able to find the solution to the problem

in my previous script below

previous_month<-sum(June_count$Tranx_count)
recent_month<-sum(July_count$tranx_count)
formula =(recent_month-previous_month)/previous_month
formula<-scales::percent(formula)

#creating dataframe
robo<-data.frame(" " = c("last_2_month:","Recent Month:", "% Increase:"),
                 " " = c(" "," "," "))

#adding variable to the dataframe using glue package   
    robo<-data.frame(" " = c(glue::glue("{last_2_month:}"),glue::glue("{Recent Month:}"), "% Increase:"),
                     " " = c(glue::glue("{previous_month}"),glue::glue("{recent_month}"),
                             glue::glue("{formula}")))

using glue library, the colon is not supposed to be in the curly bracket which is the reason why I was having the error stated.

the moment I edited the script, it works perfectly fine..see the newly edited script below

previous_month<-sum(June_count$Tranx_count)
recent_month<-sum(July_count$tranx_count)
formula =(recent_month-previous_month)/previous_month
formula<-scales::percent(formula)

#creating dataframe
robo<-data.frame(" " = c("last_2_month:","Recent Month:", "% Increase:"),
                 " " = c(" "," "," "))



#adding variable to the dataframe using glue package   
    robo<-data.frame(" " = c(glue::glue("{last_2_month}"),glue::glue("{Recent Month}"), "% Increase:"),
                     " " = c(glue::glue("{previous_month}"),glue::glue("{recent_month}"),
                             glue::glue("{formula}")))
Yomi.blaze93
  • 401
  • 3
  • 10