I am currently using Python and R together (using rmagic/rpy2) to help select different user input variables for a certain type of analysis.
I have read a csv file and created a dataframe in R. What I have also done is allowed the users to input a number of variables of which the names must match those in the header (using Python).
For example if I create a data frame as such
%R data1 <- read.csv(filename, header =T)
I then have a number of user input variables that are currently strings in pythons that would look like this.
var_1 = 'data1$age'
var_2 = 'data1$sex'
How can I then use this string as runable code in R to reach into the correct column of the data frame as such:
%R variable1 <- data1$sex
Currently I have tried the assign function and others (I understand this might be far from the mark) but I always just get it coming out as such:
%R -i var_1 assign('variable1', var_1)
%R print(variable1)
"data1$age"
I understand that I could assign values etc in R but I'm questioning if it is possible to turn a string into a runnable bit of code that could reach into a data.frame.