Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve R package workspace detection and/or warn users #633

Open
mcanouil opened this issue Jan 13, 2025 · 7 comments
Open

Improve R package workspace detection and/or warn users #633

mcanouil opened this issue Jan 13, 2025 · 7 comments

Comments

@mcanouil
Copy link
Contributor

Quarto Preview behaviour is changed depending on the context.
For instance, when a DESCRIPTION file (with Package or Type fields) is found at the root of the workspace/project, --embed-resources is added to the command which lead to issues if not in the context of single file project (default type), such as website, books, etc.

Users should be informed when an R package workspace has been detected.

Alternatively, the logic could be extended to look for _quarto.yml as this file should not be there in an R package which would mean it's a Quarto project not an R package.

  • export async function isRPackage(): Promise<boolean> {
    const descriptionLines = await parseRPackageDescription();
    if (!descriptionLines) {
    return false;
    }
    const packageLines = descriptionLines.filter(line => line.startsWith('Package:'));
    const typeLines = descriptionLines.filter(line => line.startsWith('Type:'));
    const typeIsPackage = (typeLines.length > 0
    ? typeLines[0].toLowerCase().includes('package')
    : false);
    const typeIsPackageOrMissing = typeLines.length === 0 || typeIsPackage;
    return packageLines.length > 0 && typeIsPackageOrMissing;
    }
@benesom
Copy link

benesom commented Feb 10, 2025

What is the reasoning for changing the behavior of Quarto Preview when being in the root of an R package? What is the benefit of rendering the documents with the --embed-resources options in this context?

I usually like to perfom some adhoc analysis, say located in ./analysis, when developing an R package. I currently need to preview the quarto documents in ./analysis from the command line because of the logic that you describe above.

+1 to inform users about the different behavior because it took me a couple of minutes to figure out why Quarto Preview behaved differently.

@juliasilge
Copy link
Collaborator

The reasoning is so that we get correct/expected behavior for README.Rmd and files in /vignettes.

@mcanouil
Copy link
Contributor Author

@benesom Why do you have ./analysis inside your R package? This is not expected in an R package.
The behaviour change implemented here assumed you follow R package standard structure.

If you are using an IDE like VSCode, Codium, or Positron, instead you might want to create a workspace with the two directories as workspaces: your R package AND your "analysis.

@benesom
Copy link

benesom commented Feb 11, 2025

Thanks for the swift response. I'm aware that an ./analysis directory is not expected inside an R package. However, it's a convenient structure to re-use shared components, implemented in the package, across different analysis. For smaller projects I also don't want to maintain two git repositories. I'm aware that I can simply move the R package inside its own directory :).

I can always export the package, without the analyses, at at a later point.

@cderv
Copy link
Contributor

cderv commented Feb 11, 2025

Why do you have ./analysis inside your R package? This is not expected in an R package.

To my knowledge, idea of using R package for a research compendium has been around for a long time (Bryan et al. (2017), Marwick et al. (2018)) and some R packages on CRAN even help with that like rtools or rcompendium. In those usage, having .qmd / .Rmd inside usual package structure for analysis seems common and practical.

Other use of non-conventional package are for ShinyApps when created with golem R package. Though in this context, I don't think .qmd / .Rmd would be used differently than through vignettes.

Another example is having a book inside a R Package like historically the bookdown package which has the Bookdown book leaving in the same package for convenience (and added to .RbuildIgnore so not shipped with bundled package and only in source).

I agree that there could be other ways to do it and clearly separate project. Though, possibly the detection should be made clever enough to account for those different use case. To me, this is worth thinking more about the proper solution for this 🤔

@juliasilge
Copy link
Collaborator

As a workaround for now, the current R package detection in the Quarto extension will not treat your workspace with the R package --embed-resources behavior if you specific a "Type" that is not "Package". So for example, if the project is a bookdown book, you could use "Type: Book" like this example; you can still do devtools::load_all() and similar in the project.

@benesom
Copy link

benesom commented Feb 18, 2025

It's then not possible anymore to run R CMD CHECK. At least I couldn't find any information how to run the checks for "Type: Book"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants