[R] Function to save results
Rui Barradas
ruipbarradas at sapo.pt
Wed Nov 1 19:12:21 CET 2017
Hello,
If cat is giving you an error try print(attr <- ...etc...)
Hope this helps,
Rui Barradas
Em 01-11-2017 17:21, Priya Arasu via R-help escreveu:
> Hi David,Thank you for the example.When I try to use the cat function, I get an error
>
> cat(attr<-getAttractors(net, type="asynchronous"))Error in cat(attr <- getAttractors(net, type = "asynchronous")) :
> argument 1 (type 'pairlist') cannot be handled by 'cat'
>
> Please let me know, if I have used the function in right way?.
> Thank you
> Priya
>
>
>
>
>
>
>
>
>
> On Wednesday, 1 November 2017 9:32 PM, David L Carlson <dcarlson at tamu.edu> wrote:
>
>
> Let's try a simple example.
>
>> # Create a script file of commands
>> # Note we must print the results of quantile explicitly
>> cat("x <- rnorm(50)\nprint(quantile(x))\nstem(x)\n", file="Test.R")
>>
>> # Test it by running it to the console
>> source("Test.R")
> 0% 25% 50% 75% 100%
> -2.4736219 -0.7915433 -0.1178056 0.7023577 2.9158617
>
> The decimal point is at the |
>
> -2 | 510
> -1 | 7631110
> -0 | 9988777333333211
> 0 | 01124455557777889
> 1 | 00045
> 2 | 19
>
>>
>> # Now run it and save the file
>> sink("Testout.txt")
>> source("Test.R")
>> sink()
>>
>> # What is located in "Testout.txt"?
>> cat(readLines("Testout.txt"), sep="\n")
> 0% 25% 50% 75% 100%
> -2.47511893 -0.47919111 0.05761628 0.67403447 1.79825459
>
> The decimal point is at the |
>
> -2 | 5
> -2 | 4
> -1 |
> -1 | 432000
> -0 | 87755
> -0 | 4433332110
> 0 | 001244
> 0 | 55666667777789
> 1 | 113
> 1 | 5788
>
>> # Success
>
> Depending on your operating system, you may also be able to save the output with File | Save to File.
>
> ---------------------------------------
> David L Carlson
> Department of Anthropology
> Texas A&M University
> College Station, TX 77843-4352
>
> -----Original Message-----
> From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Priya Arasu via R-help
> Sent: Wednesday, November 1, 2017 9:57 AM
> To: Eric Berger <ericjberger at gmail.com>
> Cc: r-help at r-project.org
> Subject: Re: [R] Function to save results
>
> Hi Eric,Thanks for the explanation. Is there a way to save the results automatically after the analysis gets over?. As I recently lost the results, because I didn't save the results. I don't want to run the sink or save command after the analysis is over rather run the command for saving the file before starting to run the analysis, so the file gets saved automatically after the script has finished running Priya
>
>
>
> On Wednesday, 1 November 2017 7:53 PM, Eric Berger <ericjberger at gmail.com> wrote:
>
>
> Hi Priya,
> You did not follow the logic of the pseudo-code. The sink("filename"), sink() pair captures whatever output is generated between the first sink statement and the second sink statement.You need (possibly) to do:
> sink("C://Users//Priya// Desktop//Attractor analysis_all genes//synaptogenesis//attr. txt") net <- loadNetwork("C://Users//Priya/ /Desktop//Attractor analysis_all genes//synaptogenesis// regulationof_dopamine_ signaling_submodule3.txt")attr <- getAttractors(net, type="asynchronous")
> sink()
> HTH,Eric
>
>
>
>
>
> Hi Eric,I tried as you suggested but I could not find the output in the text file I created (attr.txt)
>
> net <- loadNetwork("C://Users//Priya/ /Desktop//Attractor analysis_all genes//synaptogenesis// regulationof_dopamine_ signaling_submodule3.txt")sink("C://Users//Priya// Desktop//Attractor analysis_all genes//synaptogenesis//attr. txt")
>
>
> sink()
>
> attr <- getAttractors(net, type="asynchronous")
> Priya
>
>
> On Wednesday, 1 November 2017 6:54 PM, Eric Berger <ericjberger at gmail.com> wrote:
>
>
> Some comments:1. sink() does not return a value. There is on point to set attr <- sink(...). Just give the command sink("C://....etc")2. to complete the saving to the file you must give a second sink command with no argument: sink()So your code would be (pseudo-code, not actual code) sink( "filename" )do something that prints output which will be captured by sinksink() HTH,Eric
>
>
> On Wed, Nov 1, 2017 at 1:32 PM, Priya Arasu via R-help <r-help at r-project.org> wrote:
>
> Hi,I want the results to be saved automatically in a output text file after the script has finished running.
>
> I used the sink function in the following example, but the results file (output.txt) was empty.
>
> net <- loadNetwork("C://Users//Priya/ /Desktop//Attractor analysis_all genes//synaptogenesis// regulationof_dopamine_ signaling_submodule3.txt")# First I loaded theinput file for which I want to identify attractors attr <- sink("C://Users//Priya// Desktop//Attractor analysis_all genes//synaptogenesis//output. txt")# used the sink function to save the results from attr function
>
> attr <- getAttractors(net, type="asynchronous")# then ran the script for identifying attractors Is there any function to save the results before setting the script to run, so that results are automatically saved in a text file after the script has finished running?
>
> Thank youPriya
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________ ________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
>
>
>
>
>
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>
More information about the R-help
mailing list