Q:

R Language: Replace text with it's own modified version

I have CSV file with delimiter tabulation (\t symbol).  And I need to convert it to CSV with delimiter comma (,).  But simple replace would not work, because my text might contain comas which will break file formatting.  To avoid that I need to place such a text with comma into quotes (") and only then replace all tab symbols with comma (,). 
Each column captured between two symbols: Beginning of the file, End of the file, \t and \n.  
What I need is: if the column contains comma (,) then replace it with the same text but also put it in additional quotations.  Example:
My text, ABC\tYour pans are gray\tGood weather\n
blue flowers\tTemp, hot toaster\tOh my Sun\n

So after replacement text would look like
"My text, ABC"\tYour pans are gray\tGood weather\n
blue flowers\t"Temp, hot toaster"\tOh my Sun\n

\t in is TAB symbol

A:

I think you don't have to do this.  If you read the file as tab-separated and write it as comma-separated it will automatically handle this.  Try, 
df <- read.table(text = text, sep = "\t")
write.csv(df, 'temp.csv', row.names = FALSE)

data
text <- "My text, ABC\tYour pans are gray\tGood weather\n
         blue flowers\tTemp, hot toaster\tOh my Sun\n"

