How do I insert variables into R twitteR updates?
I use the twitteR package in R to update my twitter status with the analysis results. The static tweet function works:
library(twitteR) sess = initSession('username','password') tweet = tweet('I am a tweet', sess)
However, when I add a variable to display some specific results, I get an error.
library(twitteR) sess = initSession('username','password') res = c(3,5,8) msg = cat('Results are: ', res, ', that is nice right?') tweet = tweet(msg, sess)
Results in:
Error in twFromJSON(rawToChar(out)) :
Error: Client must provide a 'status' parameter with a value.
Any suggestions are greatly appreciated.
+2
a source to share
1 answer
This is what I get when I run a bit of your code:
> res = c(3,5,8)
> msg = cat('Results are: ', res, ', that is nice right?')
Results are: 3 5 8 , that is nice right?>
> msg
NULL
The problem is that it cat
prints lines to stdout rather than returning them as a string. Do you want to:
> res = c(3,5,8)
> msg = paste('Results are: ', toString(res), ', that is nice right?', sep='')
> msg
[1] "Results are: 3, 5, 8, that is nice right?"
+3
a source to share