civis is an R package that helps analysts and developers interact with the Civis Platform. The package includes a set of tools around common workflows as well as a convenient interface to make requests directly to the Civis Data Science API.
Installing and using
civis requires an API key. Instructions for creating an API key can be found here. All API keys have a set expiration date and so a new key will need to be created at least every 30 days.
Once you have created an API key, you will then need to add it to your
.Renviron so the
civis package can access it.
Then add the following line replacing the fake key
sadf8sadf9jasdf with the API key from your Civis Platform Profile:
After saving the
.Renviron file, you’ll need to restart R/Rstudio.
.Renviron file can be created in the R user home directory,
Sys.getenv("R_USER"). Typically this is
"C:/username/Documents". Open or create
notepad and add the key as above. Save with type
all files, not
.txt. Restart R/Rstudio.
❗ You must keep your API key secret. If you use version control tools, ensure you do not commit
.Renviron or any scripts in which you have hard-coded an API key.
civis package automatically generates R functions and documentation to interact with the Civis Platform when the package installs. From time to time, new API functions are added. These can be obtained immediately by re-installing the package from github:
If the dependencies are already installed (such as in docker containers), skipping dependency upgrades will be considerably faster:
civis includes functionality for both
Many useful tasks will require making multiple direct calls to the API.
civis includes a number of wrapper functions to make common tasks like IO and modeling easier. For example, reading data from a table in Platform is as easy as
civis includes many more functions for tasks like writing data to tables and files as well as for creating reports. For more detailed documentation, see the included vignettes:
Functions which make direct calls to the API are prefixed with the name of the resource that the function accesses. For example, the
users resource encapsulates all the functionality of Platform regarding users. We can make various calls to the
users resource to get information about ourselves and our team.
Contributions to the code are very welcome! Issues and bug reports can filed through the standard Github issue interface.
R CMD checkmust pass, i.e. using
Adding the environment variable
R_CLIENT_DEV = "TRUE" to
.Renviron will prevent new API functions and documentation from being generated based on your API Key. The default generated API functions included in the package are only updated when this package releases to CRAN.