Dynamic Environment Variable for Travis Builds

How can I change the environment variable in travis/appveyor based on an R script with every commit?

I'm developing an R package that requires an authentication token to interact with the API. The token expires after 24 hours and users are required to refresh their token with a function.

This being the case, I have tests which cause the travis/appveyor builds to fail if I haven't changed/refreshed the environment variables on both the travis/appveyor site. How can I avoid doing this with every commit that takes place 24 hours later?

I'd like to able to do something like:

  1. Commit and push some code out to GitHub
  2. Travis then runs my_function(refresh = TRUE)
  3. Travis takes the output of that function and stores it as an environment variable.