juse juse - 3 months ago 29
R Question

RMarkdown error with melt() function

I'm trying to create a file word starting from a program that on console perfectly works.

The problem is that when it reaches a function that uses

melt()
it generates an error


cannot find melt function


and stops compiling the code.

The package
reshape
is installed, and I tried to rerun the code without using markdown and it doesn't generate any error.
Is possible that RMarkdown doesn't support
melt()
function?

Answer

Installing a package is not enough — you need to load it. It’s possible that it works in your console because it was still loaded from before, or because you installed it in the current session.

To use the package, you need to add the following into your (R Markdown) code, before using any of its functions:

library(reshape)

Alternatively, you can just prefix all its functions with reshape::. So, instead of calling melt, you’d call reshape::melt. That’s less commonly done but there’s nothing wrong with it.