WFU-TLC / flc_discussion_board

A repository for discussing questions and issues in the Data Analysis with R (FLC)
https://wfu-tlc.github.io/
0 stars 0 forks source link

Trouble using .Rprofile to access key #10

Open brown-allen opened 5 years ago

brown-allen commented 5 years ago

I am having difficulty successfully accessing a key stored in my .Rprofile

I can successfully call data using the following code if I insert my Qualtrics token in place of *. `registerOptions(api_token = "*****", base_url="wakeforest.ca1.qualtrics.com") registerOptions(useLabels = FALSE) demo_survey <- getSurvey(surveyID = "SV_9vogjKXjwb7nXRr")`

However, it returns "object 'QualtricsAPItoken' not found" if I replace it with "QualtricsAPItoken" and set up the token in my .Rprofile.

This is what my .Rprofile in this project contains: `# ~/.Rprofile

Qualtrics_API

options(QualtricsAPItoken = "****") `

The following code returns TRUE in my project file: file.exists("~/.Rprofile")

But it doesn't actually find the QualtricsAPItoken. Let me know what I'm doing wrong.

Also: ropensci has a support document that suggests using a configuration file for this purpose. What are the pros/cons of a configuration file that gitignores vs. the .Rprofile?

francojc commented 5 years ago

Here's a not-to-recent rundown of various methods for storing authentication variables that may be of some help.

To me a configuration file would work fine, assuming you are going to add it to the .gitignore file.

medewitt commented 5 years ago

Yeah, while probably not best practice I use the following: in R

usethis::edit_r_profile(scope = "user")

And in my .Rprofile

qualtrics_key <-"LONG STRING"

And then I assign the object directly. This means for each new session of R this key will be available as an object. It loads some extra stuff (e.g. all of my keys appear), but I find it quicker to debug if I am missing a key (because I won't see it in my global environment pane).

Then I will use the API key in each call to the function.

demo_survey <- getSurvey(surveyID = "SV_9vogjKXjwb7nXRr", qualtrics_key)
medewitt commented 5 years ago

And another note...the registertoken things don't akways work consistently. It is more stable to use the API token in each call if it is an option. I know this is a more stable approach for several API packages I use (tidycensus, qualtRics, googleway, etc).