Creating a loop for a code replacement from a column in R

I want to copy and paste this several times but instead of the "code" included in the example, I want to include the value stored on a column from a xlsx dataset. The script I am on is R.

{
    		"entity":"sigpac",
            "code":"18142-20-237-0-1",
            "status":"ON"
    	}



For example this would be a deriable result.

[{
"entity":"sigpac",
"code":"18188-7-81-11-1",
"status":"ON"

    
    	},{
		"entity":"sigpac",
        "code":"18142-20-237-0-1",
        "status":"ON"
	

    },{
    		"entity":"sigpac",
            "code":"181232-20-237-0-1",
            "status":"ON"}
    },{
        		"entity":"sigpac",
                "code":"1315432-20-237-0-1",
                "status":"ON"}
    (etc...)

As u see, only the parameter "code" is the one that I wanna change.

THanks for the help Im learning q.q!

library(glue)

(codeval <- c(1,2,3))

(some_text_to_repeat <- glue('{{
entity":"s",
"code":"{codeval}",
"status":"ON"
}}'))

(in_a_var <- paste0("[",paste0(some_text_to_repeat,collapse=","),"]"))

#printout to console
cat(in_a_var)

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.