loading my package

Hey guys,

I am new to Rstudio and I had to create a package for a school project, it seems to work but everytime i close and reopen R I have to rebuild my package. If I try to load it with library or riquire it does not work, it returns me the folowing error:

" Error in library(testLogit) :
aucun package nommé ‘testLogit’ n'est trouvé"

The second line can be translated as "no package named 'testLogit' found". If I rebuild the package everything works perfectly. I would like to know if it is normal or if I am doing something wrong.

Ps: english is not my first linguage, but hope yous understand what I mean anyway.

:wave:, you need to install your package, not only build it, via e.g. devtools::install().

2 Likes

We'll need more information to help you figure out what's going wrong.

  • Does it only happen when you close and reopen RStudio? Or does it also happen when you restart your R session within RStudio (Ctrl+Shift+F10)?
  • What do you mean by "rebuild?" Do you mean the "install and restart" task in RStudio (Ctrl+Shift+B)? Do you mean devtools::build() and then installing it yourself with install.packages? Or something else?
  • Is there anything special about your computer setup that may affect this? Are your R libraries stored on your computer, on a shared drive, or in the cloud? You can see where they are with .libPaths().

In the meantime, you can find out more about what's happening. After rebuilding the package, run this:

ip <- installed.packages()
ip["mypackage", "LibPath"] # Replace "mypackage" with your package's name

That will show the directory where your package was installed. Make a note of it, then close and reopen RStudio. Now run this:

.libPaths()

If the directory you noted before is not shown, then something weird is happening. Without knowing more, I really cannot say what.

If the directory is shown, then something very weird is happening.

P.S.: Your English is easy to understand, so no worries.

2 Likes

The package was created on my virtual Machine for university so I dont know if there is anything special about it, it is not my personal computer.

I created it using : new Projet -> new directory -> Rpackage -> then I gave a name to my package and a path to where it is supposed to be created. ;

  • It happens when I reopen Rstudio

  • what I mean is that I have several folder in my package ( Rprojetct, main , user) and several single document, one of them is named testLogit (whiche is also the name of my package). So when I click on the testlogit document it opens Rstudio and then I go to the build tab and click on clean and reabuild and then my pacakge is availeble to use.

  • I think the libraries are stored in the computer

when I try tu run the code you gave me nwerth it returns me an error:
Error in ip["testLogit", "P:/Rs2/TestProjetR/testLogit"] :
subscript out of bounds

I hope those information can help you to help me
And thanks anyway to both of you