Icon

k_​001_​r_​export_​data

various methods to export data and graphics from KNIME with R

You could toy around with R and KNIME exports either using the generic KNIME ports or just export from inside the R nodes into graphic files, CSV files, .RDS r files, or whole environments .rdata.

URL: forum entry https://forum.knime.com/t/feeding-knime-data-output-into-rstudio/15537/2?u=mlauber71
URL: Save base graphics as pseudo-objects in R

various methods to export data and graphics from KNIME with Rhttps://forum.knime.com/t/feeding-knime-data-output-into-rstudio/15537/2?u=mlauber71 save data as .RDS file (single file from R)http://www.sthda.com/english/wiki/saving-data-into-r-data-format-rds-and-rdata rframe <- knime.in# http://www.sthda.com/english/wiki/saving-data-into-r-data-format-rds-and-rdata# define output path for vtreat 'model' and statisticspath_rds_file <- paste0(knime.flow.in[["var_path_data"]],"r_data_file.rds")path_as_txt_file <- paste0(knime.flow.in[["var_path_data"]],"path_as_txt_file.txt")# save path of RDS file in TXT filefile_with_path <- as.data.frame(path_rds_file)write.table(file_with_path, file = path_as_txt_file, sep = "\t",col.names = TRUE) # library(tidyverse)# library(gridExtra)library(ggplot2)# https://www.andrewheiss.com/blog/2016/12/08/save-base-graphics-as-pseudo-objects-in-r/var_name_pdf_file <- paste0(knime.flow.in[["var_path_graphic"]], "rplot.pdf")var_name_png_file <- paste0(knime.flow.in[["var_path_graphic"]], "rplot.png")# Scatterplotp1 <- ggplot(rframe, aes(x=x, y=y, color=z)) + geom_point()# Distributionp2 <- ggplot(rframe, aes(x=y, fill=z)) + geom_density(alpha=0.5)# p.both <- arrangeGrob(p1, p2)# grid::grid.draw(p.both)ggsave(p1, filename=var_name_pdf_file)ggsave(p2, filename=var_name_png_file)workspace_r <- paste0(knime.flow.in[["var_path_data"]],"my_workspace.rdata") create datadeterminepath and name of workflowvar_pos_namevar_path_parent_folderdetermine file separatorvar_path_dataexport graphicexport file as RDSvar_path_graphicimage.pngR Source (Table) Extract ContextProperties (deprecated) String Manipulation String Manipulation Extract SystemProperties Java Snippet(simple) R View (Workspace) Table to R Java Snippet(simple) Image Writer (Port)(deprecated) Image To Table Renderer to Image Table To Image Variable to TableRow (deprecated) Table Row to Variable(deprecated) Table Column toVariable (deprecated) various methods to export data and graphics from KNIME with Rhttps://forum.knime.com/t/feeding-knime-data-output-into-rstudio/15537/2?u=mlauber71 save data as .RDS file (single file from R)http://www.sthda.com/english/wiki/saving-data-into-r-data-format-rds-and-rdata rframe <- knime.in# http://www.sthda.com/english/wiki/saving-data-into-r-data-format-rds-and-rdata# define output path for vtreat 'model' and statisticspath_rds_file <- paste0(knime.flow.in[["var_path_data"]],"r_data_file.rds")path_as_txt_file <- paste0(knime.flow.in[["var_path_data"]],"path_as_txt_file.txt")# save path of RDS file in TXT filefile_with_path <- as.data.frame(path_rds_file)write.table(file_with_path, file = path_as_txt_file, sep = "\t",col.names = TRUE) # library(tidyverse)# library(gridExtra)library(ggplot2)# https://www.andrewheiss.com/blog/2016/12/08/save-base-graphics-as-pseudo-objects-in-r/var_name_pdf_file <- paste0(knime.flow.in[["var_path_graphic"]], "rplot.pdf")var_name_png_file <- paste0(knime.flow.in[["var_path_graphic"]], "rplot.png")# Scatterplotp1 <- ggplot(rframe, aes(x=x, y=y, color=z)) + geom_point()# Distributionp2 <- ggplot(rframe, aes(x=y, fill=z)) + geom_density(alpha=0.5)# p.both <- arrangeGrob(p1, p2)# grid::grid.draw(p.both)ggsave(p1, filename=var_name_pdf_file)ggsave(p2, filename=var_name_png_file)workspace_r <- paste0(knime.flow.in[["var_path_data"]],"my_workspace.rdata") create datadeterminepath and name of workflowvar_pos_namevar_path_parent_folderdetermine file separatorvar_path_dataexport graphicexport file as RDSvar_path_graphicimage.pngR Source (Table) Extract ContextProperties (deprecated) String Manipulation String Manipulation Extract SystemProperties Java Snippet(simple) R View (Workspace) Table to R Java Snippet(simple) Image Writer (Port)(deprecated) Image To Table Renderer to Image Table To Image Variable to TableRow (deprecated) Table Row to Variable(deprecated) Table Column toVariable (deprecated)

Nodes

Extensions

Links