Title: | Interface for Multiple Data Providers `EDDS` and `FRED` |
---|---|
Description: | Interface for multiple data sources, such as the `EDDS` API <https://evds2.tcmb.gov.tr/index.php?/evds/userDocs> of the Central Bank of the Republic of Türkiye and the `FRED` API <https://fred.stlouisfed.org/docs/api/fred/> of the Federal Reserve Bank. Both data providers require API keys for access, which users can easily obtain by creating accounts on their respective websites. The package provides caching ability with the selection of periods to increase the speed and efficiency of requests. It combines datasets requested from different sources, helping users when the data has common frequencies. While combining data frames whenever possible, it also keeps all requested data available as separate data frames to increase efficiency. |
Authors: | Sermet Pekin [aut, cre, cph] |
Maintainer: | Sermet Pekin <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.6 |
Built: | 2025-02-13 06:15:20 UTC |
Source: | https://github.com/datarapi/rapi |
Checks if the second parameter includes the first one as a value, a column name, or a name.
x %inn% table
x %inn% table
x |
Character to check if it exists in a vector or list. |
table |
List, data frame, or any vector. |
Logical value TRUE if it exists, FALSE if it does not.
.check <- "a" %inn% data.frame(a = 1:5)
.check <- "a" %inn% data.frame(a = 1:5)
Sets the cache folder or changes it if it was already set to save caches.
change_cache_folder(folder = null, verbose = FALSE)
change_cache_folder(folder = null, verbose = FALSE)
folder |
Folder to set as a cache folder. The default value is NULL, which triggers the check_users_choice_if_cache function that provides some options to the user to use it as a cache folder, a temporary one, or disable caching. |
verbose |
Boolean. If TRUE, it provides information when the cache folder is set. Otherwise, it only prints a warning when there is an error. |
No return value, called for side effects
change_cache_folder("my_cache_folder", verbose = TRUE)
change_cache_folder("my_cache_folder", verbose = TRUE)
The excel() function creates an excel file according to the object given.
data.frame
or List of data frame or Rapi_GETPREP
object can be passed..
excel( dfs = null, file_name = null, folder = null, .debug = FALSE, env = rlang::caller_env(), ... )
excel( dfs = null, file_name = null, folder = null, .debug = FALSE, env = rlang::caller_env(), ... )
dfs |
object or list of data frame to write |
file_name |
file name to save |
folder |
folder to save file |
.debug |
for internal use |
env |
environment |
... |
for future versions |
it returns object or list of dataframe
back
## Not run: excel(data.frame(a = 1:3), file_name = "test1.xlsx", folder = ".") ## End(Not run)
## Not run: excel(data.frame(a = 1:3), file_name = "test1.xlsx", folder = ".") ## End(Not run)
The get_series()
function retrieves data from various sources, including the EDDS
API and FRED
API at this version.
When multiple indexes are provided as a character vector or string template, the function individually
requests each item from the corresponding sources, discerning the source from the item's format.
The function combines data frames when there are common frequencies and returns both a combined data frame and
individual data frames for each requested item.
get_series( index = NULL, start_date = default_start_date(), end_date = default_end_date(), freq = NULL, cache = FALSE, na.remove = TRUE, verbose = NULL, ..., source = c("multi", "evds", "fred"), base = c("multi", "series", "table"), debug = FALSE )
get_series( index = NULL, start_date = default_start_date(), end_date = default_end_date(), freq = NULL, cache = FALSE, na.remove = TRUE, verbose = NULL, ..., source = c("multi", "evds", "fred"), base = c("multi", "series", "table"), debug = FALSE )
index |
A character vector or string representing the index to be retrieved. |
start_date |
Limits the start date of the data. |
end_date |
Limits the end date of the data. |
freq |
Frequency of the data (rarely needed). |
cache |
If FALSE, a new request will be made; if TRUE, cached data will be used. |
na.remove |
If TRUE, NA values are removed only if all columns are NA. |
verbose |
If TRUE, prints information during the process; if FALSE, silently does its job.
default is NULL which implies applying default verbose option. If this function is called with
a TRUE or FALSE value it changes global verbose option for |
... |
Additional parameters for future versions. |
source |
Source such as |
base |
Table or series on the source for internal use at this version. |
debug |
Debug option for development. |
An S3 object, Rapi_GETPREP, which has generic functions such as print and excel.
The print
generic provides hints to the user on how to use requested data,
such as creating output with the excel
function or examining requested data in the global environment.
## Not run: o <- get_series(template_test()) excel(o) object <- get_series("UNRATE", start_date = "2000/01/01", na.remove = TRUE) excel(object) ## End(Not run)
## Not run: o <- get_series(template_test()) excel(o) object <- get_series("UNRATE", start_date = "2000/01/01", na.remove = TRUE) excel(object) ## End(Not run)
Checks if the second parameter includes the first one as a value, a column name, or a name.
inn(x, table)
inn(x, table)
x |
Character to check if it exists in a vector or list. |
table |
List, data frame, or any vector. |
Logical value TRUE if it exists, FALSE if it does not.
.check <- inn("a", list(a = 1:5))
.check <- inn("a", list(a = 1:5))
The lag_df
function creates additional columns based on a list of column names
and lag sequences. This feature is beneficial for scenarios where you need
varying lag selections for certain columns, allowing flexibility in specifying
different lags for different columns or opting for no lag at all.
lag_df(df, laglist)
lag_df(df, laglist)
df |
A data.frame or |
laglist |
A list of column names where each index corresponds to a column name and the associated value is the lag sequence. |
tibble
df <- data.frame(a = 1:15, b = 2:16) tb <- lag_df(df, laglist = list(a = 1:5, b = 1:3))
df <- data.frame(a = 1:15, b = 2:16) tb <- lag_df(df, laglist = list(a = 1:5, b = 1:3))
The lag_df2
function creates additional columns based on a list of column names
and lag sequences. This feature is beneficial for scenarios where you need
varying lag selections for certain columns, allowing flexibility in specifying
different lags for different columns or opting for no lag at all.
lag_df2(df, laglist)
lag_df2(df, laglist)
df |
A data.frame or |
laglist |
A list of column names where each index corresponds to a column name and the associated value is the lag sequence. |
data.frame
df <- data.frame(a = 1:15, b = 2:16) df2 <- lag_df2(df, laglist = list(a = 1:5, b = 1:3))
df <- data.frame(a = 1:15, b = 2:16) df2 <- lag_df2(df, laglist = list(a = 1:5, b = 1:3))
print.Rapi_GETPREP Generic method for S3 Rapi_GETPREP object
## S3 method for class 'Rapi_GETPREP' print(x, ...)
## S3 method for class 'Rapi_GETPREP' print(x, ...)
x |
S3 Rapi_GETPREP object |
... |
further arguments passed to or from other methods. |
S3 Rapi_GETPREP object
## Not run: obj <- get_series(template_test()) print(obj) ## End(Not run)
## Not run: obj <- get_series(template_test()) print(obj) ## End(Not run)
Remove a column or columns from a data.frame.
remove_columns(df, column_names, verbose = FALSE)
remove_columns(df, column_names, verbose = FALSE)
df |
Data.frame or tibble. |
column_names |
Column name or column names as a character vector. |
verbose |
Boolean, provides extra information when removing a column. |
Data.frame.
df <- remove_columns(cars, "speed")
df <- remove_columns(cars, "speed")
This function removes rows from both ends of a data frame until it identifies
a row where all columns have non-NA
values. Starting from the beginning, it
removes rows until it encounters a row with complete data at a specific row
index (e.g., row 5).
It then proceeds to remove rows from the end of the data frame, eliminating
any rows with at least one NA
value in any column.
The process stops when it finds a row where all columns contain non-NA
values,
and the resulting data frame is returned.
remove_na_safe(df , verbose = FALSE )
remove_na_safe(df , verbose = FALSE )
df |
data.frame to remove |
verbose |
give detailed info while removing |
data.frame returns data.frame after removing rows if all columns are NA
from the beginning and after
df <- data.frame( a = c(NA, 2:7, NA), b = c(NA, NA, 5, NA, 12, NA, 8, 9) ) df2 <- remove_na_safe(df)
df <- data.frame( a = c(NA, 2:7, NA), b = c(NA, NA, 5, NA, 12, NA, 8, 9) ) df2 <- remove_na_safe(df)
set_api_key
set_api_key(key = null, source_name = null, option = c("env", "file"), ...)
set_api_key(key = null, source_name = null, option = c("env", "file"), ...)
key |
API key of the source |
source_name |
|
option |
choice of later usage. |
... |
for future versions |
The function has no return value.
## Not run: set_api_key("ABCDEFGHIJKLMOP", "evds", "env") set_api_key("ABCDEFGHIJKLMOP", "fred", "env") set_api_key("ABCDEFGHIJKLMOP", "fred", "file") ## End(Not run)
## Not run: set_api_key("ABCDEFGHIJKLMOP", "evds", "env") set_api_key("ABCDEFGHIJKLMOP", "fred", "env") set_api_key("ABCDEFGHIJKLMOP", "fred", "file") ## End(Not run)
template_test creates a string template for testing and example purposes
template_test()
template_test()
a string template that includes ID examples from different sources
template_test()
template_test()
This function turns off verbose mode, suppressing additional informational output. It is useful when you want to limit the amount of information displayed during the execution of certain operations.
verbose_off()
verbose_off()
Verbose mode is often used to provide detailed information about the
progress of a function or operation. By calling verbose_off
, you can
disable this additional output.
The options("Rapi_verbose" = FALSE)
line sets the verbose option to
FALSE
, silencing additional messages.
The function has no return value.
verbose_on
: Turn on verbose mode.
verbose_off()
verbose_off()
This function turns on verbose mode, enabling additional informational output. It is useful when you want to receive detailed information about the progress of certain operations.
verbose_on()
verbose_on()
Verbose mode is designed to provide detailed information during the execution
of a function or operation. By calling verbose_on
, you can enable
this additional output.
The options("Rapi_verbose" = TRUE)
line sets the verbose option to
TRUE
, allowing functions to produce more detailed messages.
The function has no explicit return value.
verbose_off
: Turn off verbose mode.
verbose_on()
verbose_on()