2

I created a package which gets Twitter data with the twitteR package. But to do so it needs the authentication. By now I created a .Rda file on my local system containing the Twitter handshake and placed the file in my package. But when I want to execute the function on OpenCPU it tells me:

Error: cannot open the connection

In call:
readChar(con, 5L, useBytes = TRUE)

So it seems that it can´t find the file.

  • How can I load the .Rda file in OpenCPU?
  • Can I add it to my package so that it is loaded when the package is loaded?
  • Is there a better/easier way for the authentication process?

Thanks for your help

JulianHi
  • 286
  • 2
  • 4
  • 14

1 Answers1

0

The easiest way to include objects in an R package is by placing them in the data folder of your source package. See writing R extensions 1.1.6. The appdemo package also has some examples. If you want to automatically load the data when the package is loaded you need to set LazyData: true in your package DESCRIPTION.

The best way to design authentication depends on the design of your system. In public applications it makes sense that the client supplies the authentication credentials as a function argument. If you want your server to read credentials from disk somewhere, make sure you allow this file in the security policies, see section 3.5 of the server manual.

Jeroen Ooms
  • 31,998
  • 35
  • 134
  • 207
  • Thank you for you help. It got me a step further. In R I use the code data(auth, envir=environment()) registerTwitterOAuth(twitCred) When I run it locally it works finde. Lazyload loads the data and the commands load it into the environment. But when I call the function in the OpenCPU cloud I get the following error: Error: object 'twitCred' not found In call: inherits(oauth, "OAuth“) So it seems like it can´t find the object twitCred which is in the auth.Rda file. – JulianHi Apr 25 '14 at 18:24
  • Can you post your example code somewhere so I can help you debug the problem> Also it is conventional to give the data file the same name as the object, i.e. `twitCred.rda` contains an object `twitCred`. – Jeroen Ooms Apr 25 '14 at 19:18
  • After changing the name of the .rda file to twitCred, the function call seems to work. But now I have another problem: It does not show the created html in the main page. I uploaded my code to https://github.com/JulianHill/TimelineVieweR The main page is in the directory /inst/www It calls the R function, which creates the output index.html and places it in a div. But the div stay empty. Do you know why? I thing it is because of missing js files. So how should I set the paths or where to place the js files? – JulianHi Apr 26 '14 at 18:13