I've got an R script that works fine on its own to scrape tweets using the twitteR package. But when I try to automate this script on my mac using the crontab
command, I get this error message:
/Users/Simon/WLU/projects_folder/ON18/get_tweets.R: line 1: syntax error near
unexpected token `twitteR'
/Users/Simon/WLU/projects_folder/ON18/get_tweets.R: line 1: `library(twitteR)'
Do I need to add a #/usr/bash
command or something like that to initialize the R script?
library(twitteR)
options(httr_oauth_cache=T)
consumer_key<-'yYol52znZBdtxnwQFpekMyCek'
consumer_secret<-'UMo8h70zYtrd5HSnjCGw1hnG88kfPmvu1wWxL1VvPWVYwpguu6'
access_token<-'1102181509-5hBh8OE7Ehz5NhWVBqpk1olp1dOmWiIK5B9ypzy'
access_token_secret<-'XbYZYWuMGHT5wCDzvDsDHMX3wI5KDzBJ9NQsh1Jj6I'
setup_twitter_oauth(consumer_key, consumer_secret, access_token,
access_token_secret)
#Get #onpoli tweet
onpoli<-searchTwitter('#onpoli', resultType='recent', n=200)
#Get pcoldr
pcpoldr<-searchTwitter('#pcpoldr', resultType='recent', n=200)
#Get PCPO tweets
pcpo<-searchTwitter('#pcpo', resultType='recent', n=200)
#Turn to data.frames
onpolidf<-twListToDF(onpoli)
pcpoldrdf<-twListToDF(pcpoldr)
pcpodf<-twListToDF(pcpo)
#Write out to .csv files
write.csv(onpolidf, './Tweets/onpoli.csv', append=T)
write.csv(pcpoldrdf, './Tweets/pcpoldr.csv', append=T)
write.csv(pcpodf, './Tweets/pcpo.csv', append=T)
quite(save='no')