3

Hi I am using R studio and the "knitHTML" button to convert my Rmd file into a html file. However, even thought the code runs fine, when using knitHTML it cannot find any of my objects previously created:

## Error: object 'cbt_2010' not found

however if I type cbt_2010 at the terminal - it is there. Bascially knit cannot find any of the objects in the workspace.

what am I doing wrong? it just seems any data produced in each chunk is lost in memory when using knit!

7
  • 5
    I believe knit opens its own R session, it's best for reproducibility Commented Dec 4, 2013 at 0:24
  • 2
    if you want to knit based on the objects in the current session (a possibly bad idea as @baptiste suggests), just library(knitr); knit2html("<filename>") in the console. Commented Dec 4, 2013 at 0:44
  • I think I face today a similar problem as @AleksandrBlekh. How to debug further this one? Commented Jul 14, 2016 at 11:14
  • Was a typo in my case! Commented Jul 14, 2016 at 11:26
  • @AleksandrBlekh when you load/read an object, even in-line, how do you check if it's there? Can you str(object) and/or else, like summary(object)? Commented Jul 14, 2016 at 11:32

2 Answers 2

3

As already mentioned by @BenBolker , you can use knit2html( Note that it is different from the Rstudio button, Rstudio use its own function to process document) from knitr:

 x <- 10
 writeLines(c("# hello markdown",
          "```{r hello-random, echo=TRUE}", 
               "rnorm(x)", "```"), ## note the use of x
 "test.Rmd")
 library(knitr)
 knit2html("test.Rmd")
Sign up to request clarification or add additional context in comments.

Comments

0

Maybe I am missing something in your question, but if you create object 'cbt_2010' in your .Rmd file, knitr will have that object to work with.

Stated differently, you can find it when you type object 'cbt_2010' at the console because you created that object and it is available to R. You need to do the same in the .Rmd file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.