Rmarkdown no working

Bonjour la communauté j'utilise R Studio pour de la statistique mais depuis hier j'ai un soucis avec Rmarkdown,
lorsque je le lance j'ai un souci en rapport avec un sois disant conflits avec les library. Je recherche sur google mais je suis unpeu paumé.
Please find below a screen of my R session. Thanks A loyt

You shouldn't include install commands on a Rmarkdown file, you only have to install packages once in your system, then you just have to load them, and since you are already on a Rstudio project there is no need to set the working directory either.

Also, please try to make your questions in English, since it's the preferred language here and by using French you are excluding most people from the conversation.

2 Likes

Sorry for using french.
The probleme is still. Below you will find a screen where ive delected installing packages fonctions from the script but still have issues .
The issue is on the line 14 just in the first chuck. I really dont know where it come from. I've made the script as simple as possible but nothing work

Thanks !

Where have you defined the data frame df in your R Markdown file? I see it is an object in your R Global Environment (shown on the right side of the screen). But when a R Markdown file renders, it does so in a clean R environment (without access to objects defined in the current R environment). So you need to define all objects/data frames within the R Markdown file.

That is a different issue, it's happening because you have also deleted the lines we're you load the packages and read the xlsx file so the data frame you are referencing in the code chunk (i.e. df) doesn't exist.

1 Like

I use to play it like that . I dont really get your solution .

Ive rewrite then and it work.

Am really please to have you helping me out of this issues. Thanks a lot

My solution and @andresrcs were suggesting the same thing. Any object you reference in your R Markdown file must be loaded/created in the preceding lines of code.

1 Like

copy that. But in case you may know about Librares conflit : what it is about and how to figure it out.

Thanks

What library conflicts are you referring to? Please provide more context.

Yesterday i got issues while trying to generate my RMD file. see below the issues text i dont have the screen sorry .

  • Conflicts ------------------------------------------------------ tidyverse_conflicts() -- x dplyr::filter() masks plotly::filter(), stats::filter() x dplyr::lag() masks stats::lag() Quitting from lines 36-43 (bench.Rmd) Error in df$age : objet de type 'closure' non indiçable Calls: ... withCallingHandlers -> withVisible -> eval -> eval -> summary Exécution arrêtée

Ah, okay. The library conflict is this part of the error message:

tidyverse_conflicts() -- x dplyr::filter() masks plotly::filter(), stats::filter() x dplyr::lag() masks stats::lag()

This is a little bit complicated behind the scenes, but basically when R loads the packages you have asked it to load, it checks to make sure there are no functions with the same name. If there are, then whichever package is loaded last takes priority. So in the above example, the packages dplyr, plotly, and stats all have a function called filter().

R needs a way to decide which filter() function to use when you call filter(). So since you loaded dplyr last, the dplyr version of the filter() function masks/hides the filter() function in other packages. So if you just use the filter() function, you are using dplyr::filter(). If you really wanted to use filter() from plotly or stats you would need to call them explicitly with plotly::filter() or stats::filter(), respectively.

1 Like

This is just perfect. I got it all dude. Thanks you a lot.
Is it possible to load packages in a kind of order so that i wont need to do that manipulation while using Filter functions from those libraries.

Thanks

If you really need to use a function that has the same name across multiple packages all within the same data analysis project, then the safest approach is probably to just call whichever function you need explicitly with the :: approach.

Trying to load the packages in some strategic order to avoid conflicts is not recommended, and makes it difficult to debug and understand the code. It would be hard for someone reading your code to know which filter() function is being used, if it changes throughout.

In this specific example, the plotly::filter() function is actually just exporting the dplyr::filter() function. So they will do the same thing no matter what. The stats::filter() function is very different in its use, so if you need to use it in a script along with dplyr, be explicit.

2 Likes

Copy all that.
Thanks :blush:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.