code_to_find: * string or integer with a pattern value to search within the file
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
Returns
string with a file path containing a code
Details
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)
Examples
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 codefile_i_need <- util_find_file_with_code(files = files_chr, code_to_find =9142301)# find the path to the file with a character codefile_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 filesfile_i_need <- util_find_file_with_code(files = files_chr, code_to_find ='Banana')# define a vector with settings to searchv_par <- c("StartHour")v_val <- c(15)# Replace integer valuesfile_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 searchv_par <-"UseMAFilter"v_val <-FALSE# Replace boolean valuesfile_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 filefile.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)