Skip to content
Snippets Groups Projects
Commit ba294ed6 authored by dj44vuri's avatar dj44vuri
Browse files

adapted lookup function to savely pass becoeff to next functions

parent 5fccd92c
No related branches found
No related tags found
No related merge requests found
......@@ -25,7 +25,7 @@ sim_choice <- function(designfile, no_sim = 10, respondents = 330, u ,designtype
bcoeff <- bcoeff_result$bcoeff
bcoeff_lookup <- bcoeff_result$bcoeff_lookup
browser()
u <- purrr::map(u, function(utility_group) {
purrr::map(utility_group, function(utility) {
# Convert the RHS of the formula to a single string
......
......@@ -113,22 +113,30 @@ make_md <- function(f=file){
#'
#' @keywords internal
modify_bcoeff_names <- function(bcoeff) {
# Check if bcoeff names need modification
if (any(grepl("[._]", names(bcoeff)))) {
# Create a lookup table
bcoeff_lookup <- tibble::tibble(
original = names(bcoeff),
modified = stringr::str_replace_all(names(bcoeff), "[._]", "")
)
# Modify the names in the original bcoeff
names(bcoeff) <- bcoeff_lookup$modified
# Check if bcoeff already has a lookup table attribute
if (!is.null(attr(bcoeff, "bcoeff_lookup"))) {
message("bcoeff_lookup already exists; skipping modification.")
# Retrieve the existing lookup table
bcoeff_lookup <- attr(bcoeff, "bcoeff_lookup")
} else {
# No modification needed; create a trivial lookup table
bcoeff_lookup <- tibble::tibble(
original = names(bcoeff),
modified = names(bcoeff)
)
# Check if bcoeff names need modification
if (any(grepl("[._]", names(bcoeff)))) {
# Create a lookup table
bcoeff_lookup <- tibble::tibble(
original = names(bcoeff),
modified = stringr::str_replace_all(names(bcoeff), "[._]", "")
)
# Modify the names in the original bcoeff
names(bcoeff) <- bcoeff_lookup$modified
} else {
# No modification needed; create a trivial lookup table
bcoeff_lookup <- tibble::tibble(
original = names(bcoeff),
modified = names(bcoeff)
)
}
# Attach the lookup table as an attribute to bcoeff
attr(bcoeff, "bcoeff_lookup") <- bcoeff_lookup
}
# Return both modified bcoeff and lookup table
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment