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")
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.
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.
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)
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.
The simplest solution using only base would have to be:
writeLines(text = code, con = 'C:/Users/Desktop/code_result.txt')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With