This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
suppressPackageStartupMessages(library(rvest))
suppressPackageStartupMessages(library(stringr))
suppressPackageStartupMessages(library(lubridate))
site <- read_html("https://www.submarino.com.br/produto/132128903/smart-tv-led-49-lg-49lj5500-full-hd-conversor-digital-wi-fi-integrado-1-usb-2-hdmi-webos-3.5-sistema-de-som-virtual-surround-plus?WT.srch=1&epar=bp_pl_00_go_g35164&gclid=EAIaIQobChMI2u-6y8PQ2gIVjIORCh3zkAyXEAQYASABEgKr6vD_BwE&opn=XMLGOOGLE&sellerId=00776574000660")
preco <- site %>%
html_nodes(css = ".sales-price") %>%
html_text() %>% str_remove_all(pattern = "[R$]") %>% str_remove_all(pattern = "[\\.]") %>%
str_replace(pattern = "[\\,]", replacement = "\\.") %>%
as.numeric()
hora <- now()
#cat(as.character(hora), " ", preco, "\n", file= "~/precos/robot.txt", append=TRUE)
cat(hora%>% as.character, preco, sep = ",", fill= TRUE)
#*/5 * * * * Rscript/home/precos/robot.R>>/home/robot2.txt
You can also embed plots, for example:
library(readr)
library(ggplot2)
a <- read_csv("precos.csv", col_types = cols(hora = col_time(format = "%H:%M:%S"),
tempo = col_date(format = "%Y-%m-%d")))
require(lubridate)
## Loading required package: lubridate
##
## Attaching package: 'lubridate'
## The following object is masked from 'package:base':
##
## date
a$tempo <- parse_date_time(a$tempo, "y/m/d")
plot1 <- ggplot(data = a, aes(x= tempo, y= price), geom = "line") + geom_line(color = "red") + labs(x= "Date", y = "price TV")
plot1
Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.