-1
$\begingroup$

I am attempting to compile code using Knitr in R.

My code below is returning the following error, and causes errors in the rest of the document.

miss<-sample$sensor_glucose[!is.na(sample$sensor_glucose)]
# Error: "## Warning: is.na() applied to non-(list or vector) of type 'NULL'"

str(miss)
# int [1:103] 213 113 46 268 186 196 187 153 43 175 ...

Does anyone know how to remedy this problem?

Thanks in advance!

$\endgroup$
  • 1
    $\begingroup$ Have you tried running that code in pure R, not Knitr? It seems to be more of an R problem and rather than a rendering to graphics problem. $\endgroup$ – mike1886 Aug 7 '14 at 15:14
  • $\begingroup$ The code produces no error when run in R. $\endgroup$ – Ivoire Aug 7 '14 at 15:40
  • 1
    $\begingroup$ As it stands, this example is not reproducible and therefore nobody can help you. Can you provide a minimal working example (MWE) of your .Rmd file that replicates the error? Chances are, constructing the MWE will also help you figure out what the problem is. However, my guess is that you aren't loading your data anywhere in the code. Knitr searches a new environment and not the current global environment, so you will need to re-load all packages and objects you plan to use. $\endgroup$ – shadowtalker Aug 7 '14 at 16:45
  • $\begingroup$ As @ssdecontrol suggests, you probably haven't created or loaded sample in the R in your document subsequent to this line. $\endgroup$ – conjugateprior Aug 17 '14 at 14:21
2
$\begingroup$

I agree with @ssdecontrol that a minimal reproducible example would be the most helpful. However, looking at your code (pay attention to the sequence Error: ... Warning: ...), I believe that the issue you are experiencing is due to an inappropriate setting of R's global warn option. It appears that your current setting is likely 2, which refers to converting warnings to errors, whereas, you, most likely want the setting 1, which is to treat warnings as such, without converting them to errors. If that is the case, you just need to set the option appropriately:

options(warn=1)  # print warnings as they occur
options(warn=2)  # treat warnings as errors

Note for moderators/administrators: This question seems not to be a data science question, but purely an R question. Therefore, I think it should be moved to StackOverflow, where it belongs.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.