Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save html result to a txt or html file

Tags:

r

I have a variable with html code.

Here what the code variable outpout in R console:

<!DOCTYPE html>
<html>
<body>

<h1>My First Heading</h1>

<p>My first paragraph.</p>

</body>
</html>

I try to save the content into a txt file

 write.table(code, file='C:/Users/Desktop/code_result.txt')

But it stacks with this error:

Error in as.data.frame.default(x[[i]], optional = TRUE) : 
  c("cannot coerce class \"c(\"HTMLInternalDocument\", \"HTMLInternalDocument\", \"XMLInternalDocument\", \" to a data.frame", "cannot coerce class \"\"XMLAbstractDocument\")\" to a data.frame")
like image 964
Berbery Avatar asked Dec 25 '15 13:12

Berbery


People also ask

Can I save an HTML as a file?

Right-click within the HTML document, click File > Save As. In the Save As dialog box, specify the file name and location, then click Save.

What should I save my HTML file as?

Select File > Save as in the Notepad menu. Name the file "index.htm" and set the encoding to UTF-8 (which is the preferred encoding for HTML files). Tip: You can use either .htm or .html as file extension. There is no difference; it is up to you.

Where do I save HTML form data?

HTML web storage provides two objects for storing data on the client: window.localStorage - stores data with no expiration date. window.sessionStorage - stores data for one session (data is lost when the browser tab is closed)

How do I save an HTML file after editing?

When you are done editing the HTML document, click File in the menu bar at the top of the screen. Click Save. It's in the drop-down menu below File. This saves your HTML document.


1 Answers

The simplest solution using only base would have to be:

writeLines(text = code, con = 'C:/Users/Desktop/code_result.txt')
like image 108
Inhabitant Avatar answered Oct 17 '22 15:10

Inhabitant