Good moorning
I would like to know if there is a way to find where a package is installed.
Actually, I am currently documenting a package. In my package, I have a function called "read.myfile" which reads a specific kind of file (roughly like read.table).
I have an instance of this kind of file named "myfile.txt" in my package's folder. On my documentation, I want to run an executable example of this function.
That's why I need the path, where the user has installed the package. So with this path, I can obtain the path of the file "myfile.txt" and use the function "read.myfile" in the .Rd help file, which gives help about the function "read.myfile".
Thus my example will be executable wherever the user has installed the package.
I hope my message was clear.
I don't know if it's possible to do that, but if anyone knows, thanks for helping me.
Use the function system.file.
For example:
system.file(package="ggplot2")
[1] "C:/Users/Andrie/Documents/R/win-library/3.0/ggplot2"
You can use installed.packages and subset to get the only the location of the library in which it is installed:
installed.packages()["tools","LibPath"]
[1] "C:/Program Files/R/R-2.15.2/library"
Related
Beginner to R! Bit of a bizarre question, but is anyone familiar with the compareGroups package in R? There's a function to export files, but I have no idea where the file ends up in - can't seem to find it doing a computer search. (I use RStudio). The CRAN guide wasn't particularly helpful.
The functions I tried were export2csv() and export2word()
Thank you!
Found a solution. Oddly the formula doesn't follow instructions in the package's manual. In case anyone else gets the same problem, export2word(createTable(compareGroups(x ~ y1 + y2, data=dataset), file="filename.doc")
If you run
getwd()
you should get back the directory path that RStudio is using for your current project at that moment. If you do not specify a special destination for the export, I believe it should output it in that directory. You can also run
list.files()
to list the files in your current working project directory
I made a package in R called "my_package_name". When I run ?my_package_name or ??_my_package_name, no results are found. I want a help file to be loaded in the same way that ?ggplot2 loads a package help file.
I can run ?my_function_name to obtain the help files for my functions. However, this does not work with my package name, even though the description file is complete. I found that help(package = my_package_name) loads a page that contains the description file and help pages, but I would like load a page with ?my_package_name.
I would say that the easiest way is probably to run the following from the usethis package. It will create the file needed to have your package documentation
usethis::use_package_doc()
I suggest reading the documentation of the function to understand what's going on under the hood.
I am currently developing an R package and want it to be as clean as possible, so I try to resolve all WARNINGs and NOTEs displayed by devtools::check().
One of these notes is related to some code I use for generating sample data to go with the package:
checking top-level files ... NOTE
Non-standard file/directory found at top level:
'generate_sample_data.R'
It's an R script currently placed in the package root directory and not meant to be distributed with the package (because it doesn't really seem useful to include)
So here's my question:
Where should I put such a file or how do I tell R to leave it be?
Is .Rbuildignore the right way to go?
Currently devtools::build() puts the R script in the final package, so I shouldn't just ignore the NOTE.
As suggested in http://r-pkgs.had.co.nz/data.html, it makes sense to use ./data-raw/ for scripts/functions that are necessary for creating/updating data but not something you need in the package itself. After adding ./data-raw/ to ./.Rbuildignore, the package generation should ignore anything within that directory. (And, as you commented, there is a helper-function devtools::use_data_raw().)
I created some functions and try to build a package/library, but run into some problems. I hoped to get some advise here on this support site.
This is how I tried to built my package.
I had some functions in an R file, including roxygen2 comments.
Then in R
library("devtools")
library(roxygen2)
setwd("C:to/my/directory")
create("myPackage")
Then I put my functions file in the R folder and changed the DESCRIPTION file.
setwd("./myPackage")
document()
setwd("..")
install("myPackage")
library(myPackage)
Then, when I want to see how a function works
?function1
I see the documentation in my browser.
But when I want to use my function I get an error.
function1
Error: object 'function1' not found
function1()
Error: could not find function "function1"
Does anyone know what I am doing wrong? I am using R 3.3.1 on Windows 7.
Your help or comments are appreciated, thanks in advance!
Ben
library(utils)
a<-zip.file.extract("\\1\\1.csv",zipname="drivers.zip")
Error: could not find function "zip.file.extract"
What's going on?
zip.file.extract() is a defunct function as of R 2.14 (see ?"utils-defunct" help page or try brining up the ?zip.file.extract help page). Use the unzip() function instead. Perhaps
unzip("drivers.zip", files="\1\1.csv")
or you can omit the files= to extract all files in the zip archive to the current working directory.