I am working on a making a package in RStudio. I already have it as a project, and I am using Git for version control. My directory structure is currently
--Project
--R
--.git
With the R code in the R directory.
My problem occurs when I go to build the package. I want to call the package "Project" and I get the a directory structure like this:
--Project
--R
--.git
--Project
--man
--R
And in this setup there are two sets of R files, on in each "R" directory. The less nested one is being versioned by Git, the more nested one is the source for the package. Is there some way to get the package to just use the preexisting "R" directory? Can I just reanme my current "Project" directory to something else, make the package as "Project" and then copy the .git directory to the new Project directory?
In RStudio (I'm using v. 1.0.136), this can be done via the menu options Tools > Project Options > Build Tools. Select Package from the drop-down list for Project build tools, and if you know what you're doing, fill in any of the other fields as you deem appropriate.
This operation is not going to necessarily give you the structure above i.e. man and R folders or a DESCRIPTION file, which can be done with the use_description() function from the usethis package.
Related
My .Rbuildignore specifies these files:
^inst/extdata$
This is a directory that holds some .csv files I use.
When I build my package with the "Install and Restart" button, these folders are included in the built package as demonstrated by:
> list.files(system.file(package = 'myPackage'), recursive = T, full.names = T)
...
[6] "C:/Users/JohnDoe/R/win-library/4.0/myPackage/extdata/df.csv"
...
However, if I build my package with the command devtools::install(), the inst/extdata folder is correctly ignored in the build process. This leads me to believe the discrepancy lies in the "Install and Restart" button. Is there any way to map this button to the devtools::install() command?
.Rbuildignore is used by the R CMD build command. If you install directly from a directory without building a tarball, it's not used. This is true for base R CMD INSTALL as well as the RStudio emulations of it.
So what you should do is to put the files somewhere else that isn't handled by R CMD INSTALL, for example in directory ignoreMe instead of a directory whose name means "install me".
If you don't want to do that, then it is possible to attach arbitrary R commands to keys in RStudio, but that's a lot of work. See http://rstudio.github.io/rstudioaddins/ if you want the details.
I want to be able to import or using a package that I'm writing in a directory ~/projects/ExamplePkg from my main Julia REPL / from another project or environment.
By ]foo I mean "use the foo command at the Julia Pkg REPL". Type ] at the Julia REPL to enter the Pkg REPL. Use ]help <command name> for more info or check the link below.
Ensure that your package has a Project.toml that gives it a UUID and names it (generate one with ]generate from the Julia REPL or with the PkgTemplates package) and that it is in a git repo with at least one commit including all the relevant files.
Then choose how you would like to use the package.
You probably want to run ]dev ~/projects/ExamplePkg:
If dev is used on a local path, that path to that package is recorded and used when loading that package. The path will be recorded relative to the project file, unless it is given as an absolute path.
If you use dev and you change the dependencies in the dev'd package, then you should probably run ]resolve in all environments that depend on the package.
Or you can run ]add ~/projects/ExamplePkg:
Instead of giving a URL of a git repo to add we could instead have given a local path to a git repo. This works similarly to adding a URL. The local repository will be tracked (at some branch) and updates from that local repo are pulled when packages are updated. Note that changes to files in the local package repository will not immediately be reflected when loading that package. The changes would have to be committed and the packages updated in order to pull in the changes.
In Julia versions <1.4: If you accidentally ]add a package before the git repo is set up correctly then you might get ERROR: GitError(Code:EUNBORNBRANCH, Class:Reference, reference 'refs/heads/master' not found). Unfortunately, Julia will probably have cached the bad repo, and you will need to remove that from ~/.julia/clones/<gibberish>/. You can find the dir to remove with grep: $ grep ExamplePkg ~/.julia/clones/*/config.
Documentation: https://julialang.github.io/Pkg.jl/v1/managing-packages/
you can try
path_to_package = "~/projects/ExamplePkg"
push!(LOAD_PATH,path_to_package)
# then use it, ExamplePkg is the package's name
using ExamplePkg
But you have to run codes above whenever you restart Julia.
reference is Workflow tips-Julia Documentation
My package is hosted in github, and user can install it through devtools::install_github.
Now I'm using pkgdown to generate documentation site, which created a 10M docs folder. Then I found devtools::install_github always download the whole master zip ball which become quite slow.
I tried to exclude the docs folder with these attempts:
.Rbuildignore, turned out it's only about bundled package, while install_github is installing source package so it doesn't work.
put package in pkg folder, put the generated docs folder out of pkg folder. However the whole master zip ball is always downloaded, even with subdir = "pkg" specified.
put development in a branch, and to create a special package branch without docs folder. Merge two branch but let package branch exclude docs folder. I tried make .gitignore to be branch specific but it doesn't seem to work. This seemed to be impossible.
My newest attempt is to create a separate repo solely for the website, just let pkgdown create the website in that folder like build_site(path = "../docsite/docs"). This should solve the problem and is simple and clean. The only imperfection is the website url will not be the usually pattern.
EDIT: with the latest version of pkgdown, there is no path parameter anymore, you need to specify it in the site configuration yaml, which works better (you don't need to specify it in every command).
I used packrat (v 0.4.8.-1) to to create a snapshot and bundle of the R package dependencies that go along with the corresponding R code. I want to provide the R code and packrat bundle to others to make the work I am doing (including the R environment) fully reproducible.
I tested unbundling using a different computer from the one I used to write R code and create the bundle. I opened an R code file in R studio, and called library(packrat) to load packrat (also v 0.4.8-1). I then called packrat::unbundle(bundle = "directory", where = "directory"), which unbundled successfully. But subsequently calling packrat::restore() gave me the error "This project has not yet been packified. Run 'packrat::init()' to init packrat". It seems like init() should not be necessary because I am not trying to create a new snapshot, but rather utilize the one in the bundle. The packrat page (https://rstudio.github.io/packrat/) and CRAN provide very little documentation about unbundling to help troubleshoot this, or that I could point users of my code to for instructions (who likely will be familiar with R, but may not have used packrat).
So, can someone please provide clear step-by-step instructions for how users of a bundled snapshot should unbundle, and then use that saved snapshot to run a R code file?
After some experimenting, I found an approach that seems to have worked so far.
I have provided users with three files:
-tar.gz (packrat bundle file)
-unbundle.R (R code file that includes a library statement to load
the packrat library, and the unbundle command for the tar.gz file)
-unbundle_readme.txt
The readme file includes instructions similar to those below, and so far users have been able to run R code using the package dependencies. The readme file tells users about requirements (R, R studio, packrat, R package development prerequisites (Rtools for Windows, XCode for Mac)), and includes output of sessionInfo() to document R package versions that the R code should use after instructions are followed. In the example below 'code_folder' refers to a folder within the tar.gz file that contains R. code and associated input files.
Example unbundle instructions:
Step 1
Save, but do not expand/unzip, the tar file to a directory.
Problems with accessing the saved package dependencies
are more likely when a program other than R or R studio
is used to unbundle the tar file.
If the tar file has already been expanded, re-save the
tar file to a new directory, which should not be a the same
directory as the expanded tar file, or a subdirectory of
the expanded tar file.
Step 2
Save unbundle.R in the same directory as the tar file
Step 3
Open unbundle.R using R studio
Step 4
Execute unbundle.R
(This will create a subfolder ‘code_folder’.
Please note that this step may take 5-15 minutes to run.)
Step 5
Close R studio
Step 6
Navigate to the subfolder ‘cold_folder’
Step 7
Open a R script using R studio
(The package library should correspond to that listed below.
This will indicate R studio is accessing the saved package
dependencies.)
Step 8
Execute the R code, which will utilize the project package library.
After the package library has been loaded using the above
steps, it is not necessary to re-load the package library for each
script. R studio will continue to access the package dependencies
for each script you open within the R studio session. If you
subsequently close R-studio, and then open scripts from within
the unbundle directory, R studio should still access the
dependencies without requiring re-loading of the saved package
snapshot.
I would like to run R code magic in ipython notebook but was told I need to get rpy2 package installed. Not sure how to do that, please help!
It is a pain in the A-word. I get it work, but not for every PC. Please follow my process:
Set up the global environment variables.
(a). Right click "My Computer", choose "Property"
(b). Choose "Advanced System Settings"
(c). Choose "Environment Variables"
(d). Click "New..." and add the following variables:
Variable Name=R_HOME
Variable Value=~R\R-3.0.1 (This should be the folder of R. No need to go down to "bin" folder.)
Variable Name=R_USER
Variable Value=John Smith (This should be your user name to log in windows os)
Then, double click "PATH" variable to add the R folder location at the end of the sentence (separated by ";")
Install RPY2 through pre-compiled binary packages:
Provided by Christoph Gohlke
http://www.lfd.uci.edu/~gohlke/pythonlibs/
Install the binary package after downloading.
Copy core R files to the correct directory
rpy2 package will automatically dive into "bin" folder to call R.exe; however, the core R files are located one level below (64-bit: bin\x64 or 32-bit: bin\i386). For example, assuming you wish to use 64-bit R in iPython Notebook, to make RPY2 work properly, you need to make sure that you copy everything , except R.exe and Rscript.exe, to the bin folder.
Then you should be able to load rpy2, call rmagic and enjoy.