C_Mu
C_Mu

Reputation: 325

R Paste " " around string

I create a function and need to paste " " around the string, the final desired code is 'table_df' in the following code

if (exists('table_df') && is.data.frame(get('table_df'))&nrow(table_df)>0) {
tracking_sheet$var1[tracking_sheet$var2=="table_name"]<-'Completed'
} else {tracking_sheet$var1[tracking_sheet$var2=="table_name"]<-'Check'}

this is my function, but it doesnt work, mainly because of the quotes around the string part. paste('", table_df, "',sep=""), so my question is how to use paste or other function to achieve the final result 'table_df'

check<-defmacro(tracking_sheet,table_df,table_name,
expr={if (exists(paste('", table_df, "',sep="")) && is.data.frame(get(paste('", table_df, "',sep="")))&nrow(table_df)>0) {
  tracking_sheet$var1[tracking_sheet$var2==table_name]<-'Completed'
} else {tracking_sheet$var1[tracking_sheet$var2==table_name]<-'Check'}
              })
check(tracking_sheet,app_df_pivot,"T_Applications")

the code above is trying to create a summary sheet to report which dataframe is existed in the environment and if the df contains data. I am welcome to all advice and thank you!

Upvotes: 0

Views: 963

Answers (2)

C-x C-c
C-x C-c

Reputation: 1311

If you want to paste a quote, you have to escape it with "\"

paste0("\'", "example", "\'")

Upvotes: 0

Bendt Lizzy Young
Bendt Lizzy Young

Reputation: 15

I think you mean to use

paste('"', table_df, '"',sep="")

Without the closing single-quotes,

paste('", table_df, "',sep="")

evaluates to ", table_df, "

Upvotes: 1

Related Questions