conroylau / lpinfer

lpinfer: An R Package for Inference in Linear Programs
GNU General Public License v3.0
3 stars 5 forks source link

Is it going to be easy for the user to access /Examples? #87

Closed a-torgovitsky closed 4 years ago

a-torgovitsky commented 4 years ago

Suppose our user installs via:

devtools::install_github("conroylau/lpinfer")

How would they load something from the examples folder? Would they need to supply the full path to the install directory (.e.g ~/R/<version>/3.6/lpinfer/examples)? That doesn't seem so great.

Are there other options for being able to load the code in examples more easily?

conroylau commented 4 years ago

I can think of the following ways to load the codes in the example folder more easily:

  1. Use the .libPaths function to get the path for the library of the functions. Then append the string /lpinfer/example to the path. For example, I can write a function like example.path below. Users can get the path of the example folder by running the function below. Then they can browse the files in the example folder by setting it as the working directory or directly go to this folder.

    example.path <- function() {
    path0 <- .libPaths()
    path <- paste0(path0, "/lpinfer/example")
    return(path)
    }
  2. This is similar to the first method and kind of extends it. In addition to writing a function that gets the path of the example folder, I make it open an R script using the file.edit command. For instance, I can write a function that opens the example file for the dkqs procedure when the following is run. The argument of the function can be one of the testing procedures. An error is returned if the user enters some other strings.

    lpinfer::example.code("dkqs")
  3. Move the DGP files from the example folder to the R folder. In this way, they can be called in the same way as the other functions in the package. Then they can play with the functions by using the DGP and lpmodel objects from the DGPs.

  4. Write a function to direct to the example folder of the GitHub repository using the browseURL function.

On the other hand, I am going to include examples in the Roxygen line so that examples will appear in the user manual and users can run the example by using the example command like example("dkqs", package = "lpinfer"). However, I think this is less flexible because it seems that users cannot edit the example codes here when they run them.

a-torgovitsky commented 4 years ago

Thanks, these are all great suggestions. To keep things simple, I think I will just use this device when writing the vignette:

path0 <- .libPaths()
path <- paste0(path0, "/lpinfer/example")

No need to write a special function for it.

conroylau commented 4 years ago

Sure! It is now included in the vignette under the section Further Examples. Thanks!

conroylau commented 4 years ago

I have just included the examples under the example folder in the manual.

a-torgovitsky commented 4 years ago

It turns out the example folder is not preserved when the package is installed for the user. So in db74cee I moved the content of example to inst/extdata. @conroylau let me know if you see any potential problems with this.

conroylau commented 4 years ago

I see. Sorry that I didn't realize this problem before because I thought what the user will see is the same as what I get from the build command.

I did some further research and find that everything that stores under the inst/ folder will be moved to the top-level directory (based on this figure). Instead of storing the examples under inst/extdata, shall I create a new folder inst/example? Then when users install the package, the example folder will move up to the top-level directory, like what we had before. They can still use the same method that we have in the vignettes to get the path to the examples. We can also keep the folder extdata for only storing some data sets.

Thanks!

a-torgovitsky commented 4 years ago

I see, yes that is much better than my solution. Let's do that. Thanks!

conroylau commented 4 years ago

Sure! Just moved them to the new folder.

Thanks!