Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit c1f314e
Author: byron <byron@byrongibby.online>
Date:   Thu Jan 2 10:22:26 2025 +0200

    Removed the duplication of \dots

commit 8c4a166
Author: byron <byron@byrongibby.online>
Date:   Thu Jan 2 10:00:26 2025 +0200

    Fixed typos and documentation issues

commit 3babc61
Author: byron <byron@byrongibby.online>
Date:   Thu Jan 2 09:33:43 2025 +0200

    Increment version number and update contributors

commit 556b0a0
Merge: 387bb74 d684894
Author: Byron <byron@byrongibby.online>
Date:   Thu Jan 2 09:30:57 2025 +0200

    Merge pull request #37 from aidanhorn/aidan-PR/docs

    Documentation improvements

commit d684894
Author: aidanhorn <aidanhorn@gmail.com>
Date:   Wed Nov 27 11:51:40 2024 +0200

    Documentation improvements
    Note that I deleted the "providerid" argument in write_release. Please check that that won't cause a bug.

commit 387bb74
Author: byron <byron@byrongibby.online>
Date:   Wed Oct 30 07:53:16 2024 +0200

    Check for potential null when unwrapping error message (2)

commit b71be12
Author: byron <byron@byrongibby.online>
Date:   Fri Oct 18 14:49:48 2024 +0200

    Check for potential null when unwrapping error message

commit d651651
Author: byron <byron@byrongibby.online>
Date:   Wed Aug 21 11:14:38 2024 +0200

    Changes to documentation ahead of CRAN submission

commit a851ec7
Author: byron <byron@byrongibby.online>
Date:   Wed Aug 14 13:08:43 2024 +0200

    Preparation for CRAN submission

commit 3687e37
Author: byron <byron@byrongibby.online>
Date:   Sun Aug 11 19:17:12 2024 +0200

    Updated README.md

commit 8d9b6f6
Author: byron <byron@byrongibby.online>
Date:   Sun Aug 11 19:12:33 2024 +0200

    Update URLs for EconData

commit 434430e
Merge: b51b8e2 ea16a22
Author: Byron <byron@byrongibby.online>
Date:   Sun Aug 11 19:09:15 2024 +0200

    Merge pull request #35 from coderaanalytics/frg

    Switch from session to token access to backend
  • Loading branch information
byrongibby committed Jan 2, 2025
1 parent fe37ca0 commit 85a2f0b
Show file tree
Hide file tree
Showing 20 changed files with 225 additions and 260 deletions.
11 changes: 6 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
Package: econdatar
Title: Automation of Data Tasks to and from Codera Analytics' Econometric Data Services
Version: 3.1.0
Date: 2024-04-24
Authors@R: c(person("Byron", "Botha", role = c("aut", "cre"), email = "byron@codera.co.za"),
person("Sebastian", "Krantz", role = "ctb"))
Description: Automation of data tasks to and from <https://codera.co.za> econometric data services. Using this package users can download data from <https://www.econdata.co.za> directly into R (in tidy format) after signing up for a free account. <https://www.econdata.co.za> hosts a comprehensive database of South African macroeconomic data.
Version: 3.2.0
Date: 2024-08-19
Authors@R: c(person(given = "Byron", family = "Botha", role = c("aut", "cre"), email = "econdata@codera.co.za"),
person(given = "Aidan", family = "Horn", role = "ctb"),
person(given = "Sebastian", family = "Krantz", role = "ctb"))
Description: Automation of data tasks to and from <https://codera.co.za> econometric data services. Using this package users can download data from <https://www.econdata.co.za> directly into R (in tidy format) after signing up for a free account. <https://www.econdata.co.za> hosts a comprehensive database of South African macroeconomic data. For support and tutorials please see <https://econdata.co.za>.
Depends: R (>= 4.2.0)
Imports: httr, jose, jsonlite, readODS, collapse, data.table
Suggests: tcltk
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2023, Codera Analytics
Copyright (c) 2025, Codera Analytics

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ importFrom("collapse", "add_vars<-", "ckmatch", "dapply", "fmutate", "fnobs",
"frename", "get_vars<-", "qDT", "qF", "ss", "unlist2d", "vlabels",
"vlabels<-")
importFrom("data.table", "dcast", "rbindlist", "setcolorder")
importFrom("httr", "POST", "GET", "PUT", "accept", "add_headers", "accept_json",
importFrom("httr", "POST", "GET", "PUT", "DELETE", "accept", "add_headers", "accept_json",
"authenticate", "content", "content_type", "upload_file")
importFrom("jose", "jwt_split")
importFrom("jsonlite", "fromJSON", "toJSON", "unbox")
Expand Down
1 change: 1 addition & 0 deletions R/read_dataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ read_dataset <- function(id, tidy = FALSE, ...) {
}

read_econdata <- function(id, tidy = FALSE, ...) {
.Deprecated("read_dataset")
read_dataset(id = id, tidy = tidy, ...)
}

Expand Down
4 changes: 2 additions & 2 deletions R/write_database.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ write_database <- function(x, method = "update", ...) {
} else {
error <- content(response, type = "application/json")
if (response$status_code == 400) {
if (error$message == "Validation error") {
if (!is.null(error$message) && error$message == "Validation error") {
stop(toJSON(error, pretty = TRUE))
} else {
stop(error)
Expand All @@ -101,7 +101,7 @@ write_database <- function(x, method = "update", ...) {
} else {
error <- content(response, type = "application/json")
if (response$status_code == 400) {
if (error$message == "Validation error") {
if (!is.null(error$message) && error$message == "Validation error") {
stop(toJSON(error, pretty = TRUE))
} else {
stop(error)
Expand Down
8 changes: 5 additions & 3 deletions R/write_dataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ write_dataset <- function(x, method = "stage", ...) {
} else {
error <- content(response, type = "application/json")
if (response$status_code == 400) {
if (error$message == "Validation error") {
if (!is.null(error$message) && error$message == "Validation error") {
stop(toJSON(error, pretty = TRUE))
} else {
stop(error)
Expand Down Expand Up @@ -101,12 +101,13 @@ write_dataset <- function(x, method = "stage", ...) {
} else {
error <- content(response, type = "application/json")
if (response$status_code == 400) {
if (error$message == "Validation error") {
browser()
if (!is.null(error$message) && error$message == "Validation error") {
stop(toJSON(error, pretty = TRUE))
} else {
stop(error)
}
} else {
} else {
stop(error)
}
}
Expand All @@ -118,6 +119,7 @@ write_dataset <- function(x, method = "stage", ...) {
}

write_econdata <- function(x, create = FALSE, update = FALSE, stage = TRUE, ...) {
.Deprecated("write_dataset")
if (create || update) {
stop("Create and update no longer supported, please use 'write_dataset'")
}
Expand Down
84 changes: 53 additions & 31 deletions R/write_registry.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ write_registry <- function(structure, x, method = "update", ...) {

params <- list(...)
stopifnot(length(method) == 1)
stopifnot(method %in% c("create", "update"))
stopifnot(method %in% c("delete", "create", "update"))
env <- fromJSON(system.file("settings.json", package = "econdatar"))
params$env <- env

Expand Down Expand Up @@ -726,36 +726,43 @@ write_memberlist <- function(memberlist, method, params) {

write_cons_agreement <- function(cons_agreement, method, params) {
if(is.null(params$file)) {
cons_agreement_ref <- paste(cons_agreement$agencyid,
cons_agreement$id,
cons_agreement$version,
sep = "-")
data_message <-
list(unbox("#sdmx.infomodel.message.SDMXMessage"),
list(header = params$header,
structures =
list("consumption-agreements" =
list(
list(unbox("#sdmx.infomodel.registry.ConsumptionAgreement"),
list(agencyid = unbox(cons_agreement$agencyid),
id = unbox(cons_agreement$id),
version = unbox(cons_agreement$version),
name = c("en", cons_agreement$name)))))))
if (!is.na(cons_agreement$description)) {
data_message[[2]]$structures[["consumption-agreements"]][[1]][[2]]$description <-
c("en", cons_agreement$description)
if(!is.null(cons_agreement)) {
cons_agreement_ref <- paste(cons_agreement$agencyid,
cons_agreement$id,
cons_agreement$version,
sep = "-")
data_message <-
list(unbox("#sdmx.infomodel.message.SDMXMessage"),
list(header = params$header,
structures =
list("consumption-agreements" =
list(
list(unbox("#sdmx.infomodel.registry.ConsumptionAgreement"),
list(agencyid = unbox(cons_agreement$agencyid),
id = unbox(cons_agreement$id),
version = unbox(cons_agreement$version),
name = c("en", cons_agreement$name)))))))
if (!is.na(cons_agreement$description)) {
data_message[[2]]$structures[["consumption-agreements"]][[1]][[2]]$description <-
c("en", cons_agreement$description)
}
data_message[[2]]$structures[["consumption-agreements"]][[1]][[2]][["dataflow"]] <-
list(unbox("#sdmx.infomodel.datastructure.DataflowRef"),
list(agencyid = unbox(cons_agreement$dataflow$agencyid),
id = unbox(cons_agreement$dataflow$id),
version = unbox(cons_agreement$dataflow$version)))
data_message[[2]]$structures[["consumption-agreements"]][[1]][[2]][["data-consumer"]] <-
list(unbox("#sdmx.infomodel.base.DataConsumerRef"),
list(agencyid = unbox(cons_agreement$data_consumer$agencyid),
parentid = unbox(cons_agreement$data_consumer$parentid),
parentversion = unbox(cons_agreement$data_consumer$parentversion),
id = unbox(cons_agreement$data_consumer$id)))
} else {
cons_agreement_ref <- paste(params$agencyid,
params$id,
params$version,
sep = "-")
}
data_message[[2]]$structures[["consumption-agreements"]][[1]][[2]][["dataflow"]] <-
list(unbox("#sdmx.infomodel.datastructure.DataflowRef"),
list(agencyid = unbox(cons_agreement$dataflow$agencyid),
id = unbox(cons_agreement$dataflow$id),
version = unbox(cons_agreement$dataflow$version)))
data_message[[2]]$structures[["consumption-agreements"]][[1]][[2]][["data-consumer"]] <-
list(unbox("#sdmx.infomodel.base.DataConsumerRef"),
list(agencyid = unbox(cons_agreement$data_consumer$agencyid),
parentid = unbox(cons_agreement$data_consumer$parentid),
parentversion = unbox(cons_agreement$data_consumer$parentversion),
id = unbox(cons_agreement$data_consumer$id)))
if (method == "create") {
message("Creating consumption agreement: ", cons_agreement_ref, "\n")
response <- POST(params$env$repository$url,
Expand Down Expand Up @@ -791,7 +798,22 @@ write_cons_agreement <- function(cons_agreement, method, params) {
} else {
stop(content(response, type = "application/json"))
}
} else {
} else if (method == "delete") {
message("Deleting consumption agreement: ", cons_agreement_ref, "\n")
response <- DELETE(params$env$repository$url,
path = paste(params$env$repository$path,
"consumptionagreements",
cons_agreement_ref, sep = "/"),
add_headers(authorization = get("econdata_token",
envir = .pkgenv)),
content_type("application/vnd.sdmx-codera.data+json"),
accept_json())
if (response$status_code == 200) {
message(content(response, type = "application/json")$success)
} else {
stop(content(response, type = "application/json"))
}
} else {
stop("Method not implemented.")
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion R/write_release.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
write_release <- function(id, version, providerid, description, method = "release", ...) {
write_release <- function(id, version, description, method = "release", ...) {


# Parameters ----
Expand Down
14 changes: 3 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
```r
install.packages(c("remotes", "tcltk"), repos = "https://cran.mirror.ac.za")
library("remotes")
install_github("coderaanalytics/econdatar", ref = "3.0.2")
install_github("coderaanalytics/econdatar", ref = "frg")
```

Install from disk
Expand All @@ -22,21 +22,13 @@ Re-install (upgrade when new versions are available) - **start a new session aft
```r
library("remotes")
remove.packages("econdatar")
install_github("coderaanalytics/econdatar")
```

Or if selecting a particular release **(recommended)**, [see](https://github.com/coderaanalytics/econdatar/tags)

```r
library("remotes")
remove.packages("econdatar")
install_github("coderaanalytics/econdatar", ref = "3.0.2")
install_github("coderaanalytics/econdatar", ref = "frg")
```

Please see the [EconData blog](https://econdata.co.za) for in depth tutorials

## License

Copyright © 2024 Codera Pty Ltd
Copyright © 2025 Codera Pty Ltd

Available under the terms of the MIT License, see `LICENSE`.
28 changes: 15 additions & 13 deletions man/econdatar-package.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,31 @@
}
\details{

This package provides an interface to Codera Analytic's econometric data service (https://codera.co.za) and the EconData database (https://www.econdata.co.za) in particular.
This package provides an interface to \href{https://codera.co.za/}{Codera Analytics'} econometric data service and the \href{https://www.econdata.co.za/}{EconData} database in particular.
EconData enables automation of analytical workflows that depend on public domain or third-party data. It is also a leading-edge forecast management system, enabling data and model automation and best practice data and model governance. EconData supports data-sharing across databases and within institutions, codifies modelling process flows and provides user-level access control. EconData makes it easy to securely manage and share model scenarios and forecast vintages.
The EconData Registry provides a central data glossary of data concepts and the information necessary to access and interpret data and associated metadata.
The EconData Registry provides a central data glossary of data concepts and the information necessary to access and interpret data and associated metadata. The Registry can be queried through this package's \code{\link{read_registry}} function.

Codera also uses EconData to automate models, do research, and create value-added products such as interactive scenario dashboards. These dashboards and forecasts are made available to our clients.
}
\author{
%\packageAuthor{econdatar}

Maintainer: \packageMaintainer{econdatar}
}
%\references{
%~~ Literature or other references for background information ~~
%}
%%~~ Optionally other standard keywords, one per line, from file KEYWORDS in ~~
%%~~ the R documentation directory ~~
\keyword{ package }
\seealso{
https://www.econdata.co.za
https://econdata.co.za
\href{https://www.econdata.co.za}{https://www.econdata.co.za}
\href{https://econdata.co.za}{https://econdata.co.za}
}
\examples{
\dontrun{
# library(econdatar)

# Return all data sets (useful for browsing available data)
CATALOGUE <- read_database(id = "all", tidy = TRUE)

# Mining production and sales
MINING <- read_dataset(id = "MINING", tidy = TRUE)
}
}
%\examples{
%~~ simple examples of the most important functions ~~
%}
26 changes: 7 additions & 19 deletions man/read_database.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,31 @@ read_database(id, include_series = FALSE, tidy = FALSE, \dots)
\arguments{
\item{id}{Data set identifier. May be \code{"all"}}
\item{include_series}{If \code{TRUE} series (and their metadata) with obervations omitted are included in the return (series are discarded when \emph{tidy} is \code{TRUE}).}
\item{x}{A raw API return object to be tidied. Can also be done directly in \code{read_database()} by setting \code{tidy = TRUE}}.
\item{x}{A raw API return object to be tidied. Can also be done directly in \code{read_database()} by setting \code{tidy = TRUE}}

\item{\dots}{Further \emph{Optional} arguments:
\item{\dots}{Further \emph{optional} arguments:
\tabular{llll}{
\code{agencyid} \tab\tab character. Defaults to \code{ECONDATA}. Agency responsible for the metadata creation/maintenance. \cr
\code{version} \tab\tab character. Version(s) of the data (different versions will have different metadata), or \code{"all"} to return all available versions. \cr
\code{username} \tab\tab character. Web username. \cr
\code{password} \tab\tab character. Web password. \cr
}
}

\item{tidy}{logical. Return data and metadata in tidy \emph{data.table}'s (see Value), by passing the result through \code{tidy_data}.}
}
\details{
An EconData account (http://econdata.co.za) is required to use this function. The user must provide their credentials either through the function arguments, or by setting the ECONDATA_CREDENTIALS environment variable using the syntax: "username;password", e.g. \code{Sys.setenv(ECONDATA_CREDENTIALS="username;password")}. If credentials are not supplied by the aforementioned methods a GUI dialog will prompt the user for credentials.
An \href{https://econdata.co.za/}{EconData} account is required to use this function. The user must provide an API token, which can be found on the \emph{Account} page of the online portal. A GUI dialog will prompt the user for their API token. Credentials can also be supplied by setting the ECONDATA_CREDENTIALS environment variable using the syntax: "client_id;client_secret", e.g. \code{Sys.setenv(ECONDATA_CREDENTIALS="client_id;client_secret")}, when available.
}
\value{
%% ~Describe the value returned
If \code{tidy = FALSE}, an unnamed list of data frames is returned. Each data frame further has a \code{"metadata"} attribute providing information about the data set.
If \code{tidy = TRUE} a single \emph{data.table} is returned with columns for \code{"agencyid"}, \code{"id"}, \code{"version"}, \code{"name"}, and \code{"description"}.
%% \item{comp1 }{Description of 'comp1'}
%% \item{comp2 }{Description of 'comp2'}
%% ...
}
\seealso{
%% ~~objects to See Also as \code{\link{help}}, ~~~
\code{\link{write_database}}
}
\examples{
\dontrun{
# library(econdatar)
# Sys.setenv(ECONDATA_CREDENTIALS="username;password")
# Mining production and sales
MINING <- read_database(id = "MINING")
Expand All @@ -61,11 +51,9 @@ MINING <- read_database(id = "MINING", versions = "all")
MINING <- read_database(id = "MINING", include_series = TRUE)
# Return all data sets (useful for browsing available data)
MINING <- read_database(id = "all")
tidy_data(MINING)
CATALOGUE <- read_database(id = "all")
tidy_data(CATALOGUE)
}
}
% Add one or more standard keywords, see file 'KEYWORDS' in the
% R documentation directory.
\keyword{ load }% use one of RShowDoc("KEYWORDS")
\keyword{ download }% __ONLY ONE__ keyword per line
\keyword{ load }
\keyword{ download }
Loading

0 comments on commit 85a2f0b

Please sign in to comment.