Git Product home page Git Product logo

Comments (9)

Robinlovelace avatar Robinlovelace commented on July 18, 2024

In my experience file.path is only useful in specific cases where there's a conflict between Windows and Unix-alike OS paths. In this case I suggest we don't use it - will remove I get the green light...

from efficientr.

csgillespie avatar csgillespie commented on July 18, 2024

I'm happy with either.

What about mentioning file path in an rmdnote

from efficientr.

Robinlovelace avatar Robinlovelace commented on July 18, 2024

Sounds good - will do

from efficientr.

kevinushey avatar kevinushey commented on July 18, 2024

FWIW, I think the main thing worth mentioning is that if you're calling an external program, depending on how that program behaves you might need Windows \ slashes vs. / slashes (and so normalizePath() is your friend).

At the R level, using paths with / (or from file.path()) is generally the right thing to do; it's just munging those paths for e.g. calls to system() that can be tricky.

from efficientr.

csgillespie avatar csgillespie commented on July 18, 2024

@kevinushey Thanks, very helpful.

from efficientr.

richelbilderbeek avatar richelbilderbeek commented on July 18, 2024

One thing that IMHO is not covered in enough detail by Hadley's 'R Packages' is where to put raw files (pick from /inst/exdata, /vignettes, /testthat/tests), but also how to deal with finding these files. For example, when building a vignette, the folder /vignette is temporarily uses as a working directory, so a path like /inst/exdata/my_file.txt will fail there.

As an ugly workaround I end up writing functions like this:

find_path <- function(filename) {
  if (file.exists(filename)) {
    return(filename)
  }

  prefixes <- c(
    "E:/Git/Cer2016/inst/extdata/",                                    # nolint
    "/home/richel/GitHubs/Cer2016/inst/extdata/",                      # nolint
    "/home/p230198/GitHubs/Cer2016/inst/extdata/",                     # nolint
    "/home/travis/build/richelbilderbeek/Cer2016/inst/extdata/",       # nolint
    "C:/Users/Aline/Cer2016/inst/extdata/"                             # nolint
  )
  for (prefix in prefixes) {
    full_path <- paste(prefix, filename, sep = "")
    if (file.exists(full_path)) {
      return(full_path)
    }
  }
  stop(
    "find_path: ",
    "cannot find '", filename, "'"
  )
}

I hope you guys come up with some clear guidelines on this. If you haven't already written something up one this :-)

from efficientr.

csgillespie avatar csgillespie commented on July 18, 2024

Thanks. I've managed to somehow avoid this problem, so I don't much insight. Perhaps @Robinlovelace does.

I'm not sure if this fits naturally into the book, but we'll have a think.

from efficientr.

Robinlovelace avatar Robinlovelace commented on July 18, 2024

Just been looking into this. Seems inst/extdata is the right place according to the first 3 results of an internet search, the R Packages book (which says "If you want to store raw data, put it in inst/extdata") and this question

Here is a typical example, from the datapack package:

csvfile <- system.file("extdata/sample-data.csv", package="datapack")

@kevinushey I'll add your insight and fix this asap.

Many thanks for the input.

from efficientr.

richelbilderbeek avatar richelbilderbeek commented on July 18, 2024

Awesome! Thanks for the research!

from efficientr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.