"Execute R beginner"
figueroajc
New Altair Community Member
Question 1: I don't see input ports or output ports in my execute R operator. Is this something that recently changed? I just installed the R package yesterday but all the training videos I have found do make reference to these ports.
Question 2: I have an existing R script that breaks down a date/time stamp into several other numerical attributes like hour of the week (1-168), hour of the day (1-24), etc.
The script works on
I have not been able to make the script work with RM. I keep getting a message saying RM is not able to parse the code.
Here's the code that works elsewhere:
Question 2: I have an existing R script that breaks down a date/time stamp into several other numerical attributes like hour of the week (1-168), hour of the day (1-24), etc.
The script works on
I have not been able to make the script work with RM. I keep getting a message saying RM is not able to parse the code.
Here's the code that works elsewhere:
require('TimeDate')
require('xts')
df$PropertyTimestamp <- as.POSIXct(df$PropertyTimestamp, format = "%m/%d/%Y %H:%M", tz="GMT")
#Assign WeekDay
df$WeekDay <- as.POSIXlt(df$PropertyTimestamp)$wday
#Assign WeekendBinary
df$WeekendBinary <- ifelse(df$WeekDay %in% c(0,6), 1, 0)
#Assign MonthOfYear
df$MonthOfYear <- as.POSIXlt(df$PropertyTimestamp)$mon
#Assign WeekOfYear
df$WeekOfYear <- (as.POSIXlt(df$PropertyTimestamp)$yday) %/% 7
#Assign HourOfWeek
#df$HourOfWeek <- (df$WeekDay*24) + as.POSIXlt(df$PropertyTimestamp)$hour
#Assign WeekID
df$WeekID <- (as.POSIXlt(df$PropertyTimestamp)$year * 53)+ df$WeekOfYear
#Assign HourOfDay
df$HourOfDay <- as.POSIXlt(df$PropertyTimestamp)$hour
I know I need to couple this code with the rm_main = function(data) from the operator, but I don't know how I would do this.
Thanks in advance for any help you can provide
I know I need to couple this code with the rm_main = function(data) from the operator, but I don't know how I would do this.
Thanks in advance for any help you can provide
0
Best Answer
-
Hi,
there were some small changes with the latest release.
You can now directly point to an existing R file on you disk, or connect the file with the src input port on the top left side of the operator.
If you don't see any input ports, can you verify that- the extension was correctly loaded (Extensions menu -> About installed extensions -> R Scripting Extension) or via the log in your .RapidMiner folder?
- you have the data.table library installed in R?
Regarding your script:
Each input port connected to the operator is mapped to an argument of the rm_main() function (where the name is arbitrary and can be defined by you) from top to button.
In you case just connect your data to the first input port and rename the rm_main() function to rm_main(df).
Input example sets are automatically converted into a data.table (an extended version of the core data frame).
In the end, if you want to return your transformed data to RapidMiner, you need a return() statement, with the modified data.table.2
Answers
-
Hi,
there were some small changes with the latest release.
You can now directly point to an existing R file on you disk, or connect the file with the src input port on the top left side of the operator.
If you don't see any input ports, can you verify that- the extension was correctly loaded (Extensions menu -> About installed extensions -> R Scripting Extension) or via the log in your .RapidMiner folder?
- you have the data.table library installed in R?
Regarding your script:
Each input port connected to the operator is mapped to an argument of the rm_main() function (where the name is arbitrary and can be defined by you) from top to button.
In you case just connect your data to the first input port and rename the rm_main() function to rm_main(df).
Input example sets are automatically converted into a data.table (an extended version of the core data frame).
In the end, if you want to return your transformed data to RapidMiner, you need a return() statement, with the modified data.table.2