How to assign function output if variable name contains function arguments w/o use of "<<-"??

Given function is just an example. The goal is not to paste "€" per se, but to find out how to return the function output if variable name contains function arguments or arguments outside of function. Thank you in advance for help!!

####### CREATING THE DATA FRAME: ###################################################
df <- data.frame("spend" = rnorm(31, mean = 1000, sd = 300),
             "income" = rnorm(31, mean = 2000, sd = 300))

os <- c("android", "ios", "windows")
trackers <- c("Facebook", "Google", "Twitter", "Instagram")
countries <- c("de", "au", "us", "lm")

android  <- data.frame(os = "android",
                   country = countries)

ios <- data.frame(os = "ios",
              country = countries)

country_os <- rbind(android, ios)
tables2 <- list()

fn <- function(x) {
as.data.frame(country_os) %>% add_column(Tracker = x)
}

variables <- lapply(trackers, fn)
variables <- rbindlist(variables)

fn2 <- function(os, tracker, country){

tables2[[os]][[tracker]][[country]] <<- df

}
pmap(list(variables$os, variables$Tracker, variables$country), fn2)

##################### FUNCTION TO BE MODIFIED: ##########################################################

adding_euros <- function(os, tracker, country){
  
tables2[[os]][[tracker]][[country]][,2] <<- paste(tables2[[os]][[tracker]][[country]][,2], "€")

}

# How to assign the output properly  without "<<-" ???

pmap(list(variables$os, variables$Tracker, variables$country), adding_euros)

Help for how to do "fn2" alternatively much appreciated too!!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.