When you're hacking on this package locally, you can test it by installing from source:
- change into the repo's root directory
cd /path/to/git/ausplotsR/
- start R
R
- make sure
devtools
androxygen2
are installed, you only need to do this onceinstall.packages("devtools") install.packages("roxygen2")
- install the dependencies for our package:
devtools::install_deps(pkg='.')
- use the
devtools::load_all
(doco) function to load the package from source. There is no argument to this function as it looks in your current working directory:# check your working directory with # getwd() # ...and set your working directory with # setwd('/path/to/dir') devtools::load_all()
- if you make code changes, re-run
devtools::load_all()
to reload.
The load_all()
function defaults to exporting everything so you can access all
package private functions to test them.
You might also want to change the URL of the API that is used (to your local machine?). To do so, we need to set an R option:
devtools::load_all()
options("ausplotsR_api_url" = "http://localhost:30000")
#...continue to call functions
You can check the current setting of the API URL with:
getOption("ausplotsR_api_url")
You can also set an option to turn on (or off) debug logs:
options("ausplotsR_api_debug" = TRUE)
#...continue to call functions
To test that the package can install into a fresh environment, we can use a Docker container. Note that this will use the repo you have locally, but it WILL NOT use dirty working directory state. It installs clean commits only.
- start the container
cd ausplotsR/ # root of this repo docker run \ --rm \ -it \ --name=ausplotsr-test \ -v `pwd`:/app \ zamora/r-devtools
- in the container, install our package from the local source we mounted as a
volume in the container
devtools::install_git('/app', ref = 'somebranch') # ref can be branch or commit
- load our library
library(ausplotsR)
- perform any other testing you need with the library
If you prefer to use a GUI version of R, we can use an RStudio docker image:
- start the container
cd ausplotsR/ # root of this repo docker run \ -e PASSWORD=somepassword \ --rm \ --name=ausplotsr-test \ -v `pwd`:/app \ -p 8787:8787 \ rocker/tidyverse
- open your browser to http://localhost:8787
- login as
rstudio
with passwordsomepassword
- then run the install command the same as the command line version above. Or use the install from github commands.
To install a specific branch from GitHub, for example somebranch
, use the following command:
devtools::install_github("ternaustralia/ausplotsR@somebranch")
For developers: the server-side mechanism to allow this is described in the docs for the server.
By default the public (unauthorised users) can only access site visits that are marked as published in the database.
The database also contains unpublished data. If you authorise yourself, you can access these unpublished records.
Follow these steps to access the unpublished site visits:
- load the ausplotsR library like normal
- configure some authorization to prove that you're allowed to access
unpublished data. Note: this command is an example, you'll need to ask
someone who maintains the ausplotsR database for the real role and
secret values.
ausplotsR:::set_auth('somerole', 'somesecret')
- now all queries you perform will include unpublished visit data
- to return to only querying published data, run:
ausplotsR:::unset_auth()
The authorisation will expire. If you leave your R session open for a really long time, you might see an error like:
Error in .ausplots_api(path, query) : Unauthorized (HTTP 401).
If this is the case, re-run the set_auth()
function and things should start
working again.