I am working on ipython notebook to apply tf-idf and knn model. I want to save the output of below command in excel: knn_model.query(Var, k = 20) . I can see it in the notebook but dont know how to save this output in my system. Please help.
Easiest answer: Copy paste the result to a file, which you could use as input to where you want to use the result?! Using any text-editor where you opened a new file to copy into.
More complicated answer: you forget to tell where the out put has to go ... Python has lots of possibilities to export Python created output to.
Related
I am calling one R Markdown script from another R script.Below you can see command
rmarkdown::render((file=paste(path1,"/Dashboard.Rmd",sep="")),params=list(args = myarg))
The script is executed without any problem but is not open automatically.
So can anybody help me how to solve this problem and open this script automatically after running of this command ?
First, your syntax probably isn't doing what you intended. Writing
rmarkdown::render((file=paste(path1,"/Dashboard.Rmd",sep="")),params=list(args = myarg))
will create a new variable named file and use it as the first parameter to rmarkdown::render. A more likely way to get what you want is to write it as
outfile <- rmarkdown::render(paste(path1,"/Dashboard.Rmd",sep=""),
params=list(args = myarg))
This removes the assignment from the first argument, and saves the
result (which is the name of the file that was produced).
Now, on to your question: You need to follow that line with
rstudioapi::viewer(outfile)
to view it in RStudio, or
browseURL(outfile)
elsewhere, because rmarkdown::render doesn't automatically call a previewer.
I am using Jupyter Notebook to write my report and it would be convenient to include an output in my markdown.
The question below is a simillar question.
Jupyter notebook output in markdown
For example, I have a code cell with the code
In[1]: import random
a = random.randint(1,4);a
and the output was
Out[1]: 2
in my report, I would realy like to include this output just like
'the chosen number was 2'
however, as the 2 is a random number, it would be very convenient to have a way to include the variation a in my markdown like;
'the chosen number was %a'
kind of way.
Is there any way to achieve this?
It's not possible in the main notebook yet (although there are discussions about it) but there is an extension which should suit your purposes:
http://jupyter-contrib-nbextensions.readthedocs.io/en/latest/nbextensions/python-markdown/readme.html
It's contained within the ipython-contrib-extensions package, for which the install instructions are here:
http://jupyter-contrib-nbextensions.readthedocs.io/en/latest/install.html
I want to save a part of my r script output including the commands into a text file. I know sink() but it does not include the commands or I could not find a specific option to do that.
Is there any possibility to capture the commands and its ouput within an r session. Simply write an Rmd or capture the output within the console is not the solution at the moment.
You are probably looking for the TeachingDemos package. Documentation can be found here.
Example:
library(TeachingDemos)
txtStart("test.txt")
# Your code
txtStop()
This should write both your command input and output to a file called test.txt.
If you're working interactively, here's one idea. It was this specific problem for which I created the sinkstart() function in the rite package. Basically, this creates a pop-up tcl/tk widget that you can write commands and output to. Here's a screenshot to give you a feel:
There are just two relevant functions: sinkstart() starts the sink; sinkstop() turns it off. You can toggle back and forth to selectively write to the widget. Then you can just save the contents with a right-click or a key shortcut.
I'm making a simple line in r to automatically open my generated plots.
I output the plots to a file called "plots.pdf" in the same directory as my r file, and at the end i use this two lines to try to open it:
dir <- paste("/Applications/Skim.app/Contents/MacOS/Skim ",getwd(),"/plots.pdf",sep="")
system(dir)
Basically, dir concatenates the full path of the skim app and the full path of the generated plot.
If i run the string stored at dir in a shell it works perfect, it opens the pdf file in Skim, but when i run it with system() from inside R it doesn't work (Skim says 'The document “plots.pdf” could not be opened.').
I believe this is a very little mistake somewhere in the syntax regarding the absolute/relative paths, but haven't managed to find it... Any advice is welcome! (Or a better way to achieve the same)
I found a way to bypass that problem, i just changed the path to Skim for the 'open' command and i let the system to assign the default app for pdf viewing. So:
dir <- paste("open ",getwd(),"/plots.pdf",sep="")
And it works.
I want only the output not the commands, and I want to see the output on the console at the same time.
I tried sink and capture.output , but tried to work through the examples but I can accomplish only one of the task i.e. either to console or to a file.
I am new to R, and was thinking whether there is a function that can help me see the output on the console and save it to a text file as well?
Do sink(file="file.txt", split=TRUE).