View source: R/util_find_file_with_code.R
util_find_file_with_code | R Documentation |
Utility function to find the file path which contains specific code
util_find_file_with_code(
files,
code_to_find,
option_replace = FALSE,
v_settings,
v_values
)
files |
|
code_to_find |
|
option_replace |
boolean, option to indicate if function should also replace parameter values |
v_settings |
string vector with the parameters that needs to be found |
v_values |
vector with the corresponding values of the parameters |
Function is reading content of file and checks each file for a specific code Function will require a vector with a valid file paths Function will output the path to that file which contains a give code If no desired code is found, function will return NULL Optionally, if enabled, function will replace their values Note: supply same kind of parameters (either boolean or integers)
string with a file path containing a code
(C) 2024 Vladimir Zhbanko
library(readr)
dir <- normalizePath(tempdir(),winslash = "/")
file.copy(from = system.file("extdata/default", package = "lazytrade"),
to = dir, recursive = TRUE)
files_chr <- list.files(path = file.path(dir, "default"), all.files = TRUE,
pattern = ".chr", full.names = TRUE)
code_to_find <- 9142301
# find the path to the file with numeric code
file_i_need <- util_find_file_with_code(files = files_chr,
code_to_find = 9142301)
# find the path to the file with a character code
file_i_need <- util_find_file_with_code(files = files_chr,
code_to_find = 'BITCOIN')
# find the path to the file with a character code that is not exists in those files
file_i_need <- util_find_file_with_code(files = files_chr,
code_to_find = 'Banana')
# define a vector with settings to search
v_par <- c("StartHour")
v_val <- c(15)
# Replace integer values
file_i_need <- util_find_file_with_code(files = files_chr,
code_to_find = 9142301,
option_replace = TRUE,
v_settings = v_par,
v_values = v_val)
# define a vector with settings to search
v_par <- "UseMAFilter"
v_val <- FALSE
# Replace boolean values
file_i_need <- util_find_file_with_code(files = files_chr,
code_to_find = 9142301,
option_replace = TRUE,
v_settings = v_par,
v_values = v_val)
# Replace boolean values in specified file
file.copy(from = system.file("extdata/Falcon_D.set", package = "lazytrade"),
to = dir, recursive = TRUE)
file_i_need <- util_find_file_with_code(files = file.path(dir, "Falcon_D.set"),
code_to_find = 9142301,
option_replace = TRUE,
v_settings = v_par,
v_values = v_val)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.