Icon

kn_​example_​r_​source_​script

Call an .R script from a subfolder and use in a R KNIME Snippet

Call an .R script from a subfolder and use in a R KNIME Snippet
the script "example_function.R" is in the subfolder "data/my_r_scripts"

Call an .R script from a subfolder and use in a R KNIME Snippetthe script "example_function.R" is in the subfolder "data/my_r_scripts"https://forum.knime.com/t/using-r-functions/75182/2?u=mlauber71 # the script is in the sub-folder "data/my_r_scripts"# example_function.R# addNumbers <- function(df, col1, col2, newColName) {# df[[newColName]] <- df[[col1]] + df[[col2]]# return(df)# }# Main R script# Source the function from the file in the sub-foldersource(knime.flow.in[["var_path_r_script"]])# Create a data framedf <- knime.in# Specify the columns to sum upcol1 <- "Universe_0_0"col2 <- "Universe_0_1"newColName <- "sum_of_a_and_b"# Apply the function to the data framedf <- addNumbers(df, col1, col2, newColName)knime.out <- df KNIME and R — installation across operating systems — some remarkshttps://medium.com/low-code-for-advanced-data-science/knime-and-r-installation-across-operating-systems-some-remarks-6494a2a498cc locate and create/data/ folderwith absolute pathsdummy datavar_path_r_scriptCluster_Membershipcall your own .R code Collect LocalMetadata Data Generator Java EditVariable (simple) Column Rename R Snippet Call an .R script from a subfolder and use in a R KNIME Snippetthe script "example_function.R" is in the subfolder "data/my_r_scripts"https://forum.knime.com/t/using-r-functions/75182/2?u=mlauber71 # the script is in the sub-folder "data/my_r_scripts"# example_function.R# addNumbers <- function(df, col1, col2, newColName) {# df[[newColName]] <- df[[col1]] + df[[col2]]# return(df)# }# Main R script# Source the function from the file in the sub-foldersource(knime.flow.in[["var_path_r_script"]])# Create a data framedf <- knime.in# Specify the columns to sum upcol1 <- "Universe_0_0"col2 <- "Universe_0_1"newColName <- "sum_of_a_and_b"# Apply the function to the data framedf <- addNumbers(df, col1, col2, newColName)knime.out <- df KNIME and R — installation across operating systems — some remarkshttps://medium.com/low-code-for-advanced-data-science/knime-and-r-installation-across-operating-systems-some-remarks-6494a2a498cc locate and create/data/ folderwith absolute pathsdummy datavar_path_r_scriptCluster_Membershipcall your own .R codeCollect LocalMetadata Data Generator Java EditVariable (simple) Column Rename R Snippet

Nodes

Extensions

Links