Hi, On Tue, May 18, 2010 at 2:49 PM, Godavarthi, Murali <mgodavar...@dpscs.state.md.us> wrote: > Hi, > > I'm new to 'R' and need some help on the "Load" command. Any responses > will be highly appreciated. Thanks in advance! > > As per manuals, the "Load" command expects a binary file input that is > saved using a "save" command.
Or a path to the file ... > However it is required that we need to > call the 'R' program from > > Java web application using RJava, and pass a string to the 'R" program > instead of a binary file. Is it possible? Yes, pay closer attention to the description for the "file" argument in the load function (see ?load): """a (readable binary) connection **or a character string** giving the name of the file to load""" (emphasis mine) > I was exploring the options of using TextConnections, file connections > and other types of connections in order to read a stream of input > (either from a file, stdin etc). I am able to read the string, but the > Save and Load commands are not accepting the string input. Here is the > sequence of commands I tried running, and the error received. There is > no clue on this error, especially when trying to use the eval function > in randomForest package, even on the internet. Can anyone help please! > >> library(randomForest) > > randomForest 4.5-34 > > Type rfNews() to see new features/changes/bug fixes. > > > >> load("C://Program Files//R//R-2.10.1//bin//rfoutput") > > > >> zz <- file("ex.data", "w") > > > >> cat("\"imurder\" \"itheft\" \"irobbery\" \"iassault\" \"idrug\" > \"iburglary\" \"igun\" \"psych\" \"Freq\" \"priors\" \"firstage\" > \"intage\" \"sex\" \"race\" \"marstat\" \"empac\" > > \"educ\" \"zipcode\" \"suspendmn\" \"drugs\" \"alco\" \"probation\" > \"parole\"",file = zz, sep = "\n", fill = TRUE) > > > >> cat("\"10\" 0 0 0 1 0 0 0 0 0 58 19 19 \"1\" \"BLACK\" \"SINGLE\" > \"UNEMPLD\" 0 21215 0 0 0 1 0",file = zz, sep = "\n", fill = TRUE) What are you trying to do here? It looks like you want to save a table of sorts. First create your data into a data.frame, then save that data.frame to a file using write.table (or write.csv, etc). >> save(zz, file = "testmurali", version = 2) You're saving a file "object" here, not the contents of the file. Once you successfully serialize your data into a text file, just load it from "like normal" using read.table (or similar). Anyway, I'm not sure what we're talking about here, but in short: 1. You need to make sure that you are correctly saving what you think you're saving. 2. You can pass a character string to the `load` function, so you can send it through (over from) java as you wich. 3. I don't think you really want to deal with load/save here, because it looks like you are dealing with some tab delimited file -- in which case use read.table (or similar) and load it that way. You can, of course, still use save/load, but make sure you save/load the right thing (not a file object like you're doing here). -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.