This is still a work in progress, so please let me know if you have any comments, particularly as regards making it more seamless to use.
First, some basics:
- While theoretically any DBI based backend will work, currently only RMySQL and RSQLite are supported.
- The only types of data able to be persisted are tweets (status) objects and user objects. Granted, this likely covers 95%+ of use cases.
- Data can be retrieved as either a list of the appropriate object or as a data.frame representing the table. Only the entire table will be retrieved - my expectation is that it will be simpler for users to interact with data via things like dplyr.
To get started, you must register your database backend. You can either create a DBI connection from one of the supported packages or call one of the available convenience methods (which will return the connection as well as register it with twitter.
To continue, suppose we have a list of tweets we want to persist. Simply call store_tweets_db() with your list and they'll be persisted into your database. By default they will be persisted to the table tweets but you can change this with the table_name argument.
Finally, to retrieve your tweets from the database the function is load_tweets_db(). By default this will return a list of the appropriate object, although by specifying as.data.frame=TRUE the result will be a data.frame mirroring the actual table. Much like store_tweets_db() there is a table_name argument.
Note that for user data there is a mirror set of functions, store_users_db() and load_users_db(), and the default table name is users.
To continue, suppose we have a list of tweets we want to persist. Simply call store_tweets_db() with your list and they'll be persisted into your database. By default they will be persisted to the table tweets but you can change this with the table_name argument.
Finally, to retrieve your tweets from the database the function is load_tweets_db(). By default this will return a list of the appropriate object, although by specifying as.data.frame=TRUE the result will be a data.frame mirroring the actual table. Much like store_tweets_db() there is a table_name argument.
Note that for user data there is a mirror set of functions, store_users_db() and load_users_db(), and the default table name is users.
Jeff,
ReplyDeleteIf I add tweets using store_tweets_db() when these tweets were already in the db I have them double.
Is there a way to avoid storing them double? Is there a reason why I should want them to be double?
Thanks
hello ,
ReplyDeletei am facing problem in this
register_db_backend(dbi_connection)
Error: could not find function "register_db_backend"
how this can be solved..
thanks..