0

I know others have had something similar, but all their solutions didn't seem to work on what's happening with my code.

I have this code:

frq(GSS$HEALTH1)

and I've made sure the sjmisc package is installed and running for that function.

When I run that chunk on its own, I get the table.

x <integer>
# total N=5215  valid N=5215  mean=0.72  sd=1.38

Value |    N | Raw % | Valid % | Cum. %
---------------------------------------
    0 | 3767 | 72.23 |   72.23 |  72.23
    1 |  292 |  5.60 |    5.60 |  77.83
    2 |  449 |  8.61 |    8.61 |  86.44
    3 |  440 |  8.44 |    8.44 |  94.88
    4 |  207 |  3.97 |    3.97 |  98.85
    5 |   27 |  0.52 |    0.52 |  99.37
    8 |    3 |  0.06 |    0.06 |  99.42
    9 |   30 |  0.58 |    0.58 | 100.00
 <NA> |    0 |  0.00 |    <NA> |   <NA>

But when I knit, I get the following error:

Error in frq(GSS$HEALTH1) : could not find function "frq" Calls: <Anonymous> ... handle -> withCallingHandlers -> withVisible -> eval -> eval Execution halted

Anyone got thoughts to get this to run?

r2evans
  • 141,215
  • 6
  • 77
  • 149
  • Welcome to SO! To help us to help you could you please make your issue reproducible by sharing a sample of your **data**, the **code** you tried and the **packages** you used? See [how to make a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) To post your data type `dput(NAME_OF_DATASET)` into the console and copy & paste the output starting with `structure(....` into your post. – stefan Feb 03 '21 at 20:38
  • Most of the time when people have an issue with code running in the console but not when knittering it's because they missed to include the code load the data or the packages inside the Rmd. – stefan Feb 03 '21 at 20:39
  • 1
    In this case, the error is telling you that the environment in which the document is being rendered has not had that library attached/loaded. Objects and packages available in *your* development environment will not necessarily be visible to the rendering environment. I tend to have a `\`\`\`{r setup,echo=F,include=F}\nlibrary(abc)\nlibrary(qrs)\n\`\`\`` as one of the first blocks in my Rmd reports. – r2evans Feb 03 '21 at 20:46

0 Answers0