R: using package by unzipping it instead of installing it - r

I am trying to use a package which can not run at such in window Rgui. The website of the package suggests for unzip and use the function
http://mouse.cs.ucla.edu/emma/install.html
But I did not way to find where I can find the function that I can enter in my R console and use it.
Help appreciated
EDITS:
RGUi that comes with windows distribution
Packaged useed is: emma, can be downloaded from the above website

And the all-R, mouse-free version (I was almost there Roman!):
download.file("http://mouse.cs.ucla.edu/emma/emma_1.1.2.tar.gz",
destfile=paste(getwd(),"/emma/emma_1.1.2.tar.gz",sep=""))
untar(paste(getwd(),"/emma/emma_1.1.2.tar.gz",sep=""), compressed = "gzip")
source(paste(getwd(),"/emma/R/emma.R",sep=""))
wherein a new directory (emma/) will be created in your present working directory.

You can download the .tar.gz file and use untar function. I've moved the file in question to my Q drive in folder emma and ran the following command. The result was extracted to a folder called emma under my working directory.
untar("q:/emma/emma_1.1.2.tar.gz", compressed = "gzip")
After you've done that, you can source the .R files (see comments under your question).

Related

Making R package and includes Jar files in

I use RStudio to make my package. The idea is one of the functions in my R file runs a jar file using System(). it works fine using Rstudio. The problem comes with distribution. when I use devtools::install_github("package on github"). it ignores my jar file, and it doesn't download it with the rest of the package files.
I appreciate if anyone can help.

R: instructions for unbundling and using a packrat snapshot

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.

r modify and rebuild package

I'm trying to use the SemiMarkov package and I want to change one small line of code in there. I've done some digging via:
getAnywhere("semiMarkov")
& I've identified that I want to change this line:
hessian <- diag(ginv(hessian(V, solution)))
to try something like:
hessian <- diag(ginv(pracma::hessian(V, solution)))
How do I go about this? Do I need to rebuild the package from scratch, and if so do I need rTools etc for this, or is there a simple-ish workaround (I'm a relevant R novice)? I've done some searching online and can't find anything obvious. Any ideas/pointers gratefully appreciated.
If you'd like to simply test out the effect of that change in an interactive R session, you can do so using trace(). Here's how:
Type trace("semiMarkov", edit=TRUE)
In the text editor that that launches, edit the line of interest.
Save the modified file.
Close the text editor
Back in R, use the modified function.
Linux environment
Starting with downloading the package source from CRAN.
This is the landing page: https://cran.r-project.org/web/packages/SemiMarkov/index.html
This is the package source: https://cran.r-project.org/src/contrib/SemiMarkov_1.4.2.tar.gz
Download and extract the source:
wget https://cran.r-project.org/src/contrib/SemiMarkov_1.4.2.tar.gz
tar -xvzf SemiMarkov_1.4.2.tar.gz
This should result in a directory named SemiMarkov. Open up the source (cd SemiMarkov), and modify as necessary.
Next, build the changes:
cd ..
R CMD build SemiMarkov/
This will result in a new archive file named SemiMarkov_1.4.2.tar.gz.
Lastly, install your modified archive:
R CMD INSTALL SemiMarkov_1.4.2.tar.gz
Windows environment
I'm less familiar with the Windows platform. *nix tooling is available in Cygwin, but it's painful. Instead, as Josh O'Brien points out, you should follow the Windows-specific instructions in the R Installation and Administration manual.

creating package

i am creating a package in R language, everything is running properly, but when i run R CMD check , it shows an error message while running examples.. i.e.
"can't open the file." "No such file or directory"
actually my function needs a PubMed text file containing abstracts from the PubMed, i have placed my text file in every sub-directory of my package, but its not working. showing same error again and again.
so please suggest me the right way how to put a text file in a package which can be used by examples to run properly.
i will be very thankful to you.
Usually you put such data in the /inst folder. E.g.:
<packageRoot>/inst/pubmed/myfile
After the package is build you can access the content of this folder from within the package like this:
system.file( "pubmed/myfile", package="<package>" )
See for more information http://cran.r-project.org/doc/manuals/r-release/R-exts.pdf (1.1.5 Data in packages).
I suggest you to use devtools and roxygen2 packages. Basically, you just need to prepare description and .R files.
see more details in this brilliant answer :devtools roxygen package creation and rd documentation

readRDS(file) in R

Whenever I try to install a package in R, I get the following error:
Error in readRDS(file) : unknown input format
This just started occurring after I had a system crash. I am running 32 bit R 2.13.0 under windows 7. I tried removing and re-installing R, but continue to get the error. Is there any way I can fix this without deleting everything (i.e. all the packages I've installed) and starting over?
Thanks
These are suggestions I have come across:
Delete your .Rhistory and .RData files in the directory in which you are running R.
Run update.packages()
Try and detect "bad files" in your library directories. You can do this in R
# List the library paths
# The issue is likely to be in the first directory
paths = .libPaths()
## Try and detect bad files
list.files(paths,
pattern = "^00LOCK*|*\\.rds$|*\\.RDS$",
full.names = TRUE)
## List files of size 0
l = list.files(paths, full.names = TRUE)
l[sapply(l, file.size) == 0]
Delete any files/directories highlighted. You could use file.remove() if you really wanted to.
Delete the directory in which you have stored your downloaded packages.
Only solution 3 worked for me.
Ref:
R-sig-Debian mailing list
Option 3 was a combination of answers provided by different people over the last few years, including Chunxiao Xu, Larry Hunsicker and Frank Harrell
Run find /usr/local/lib/R/site-library/ /usr/lib/R/library/ /usr/lib/R/site-library/ ~/.local/lib/ -iname '*rds' -a -size 0 and then delete the files found.
Chunxiao Xu and Rando Hinn's solution above worked for me, with a minor tweak.
First, change directories to your personal R package directory, then run: find -iname '*rds' -a -size 0
Delete the directories containing any 0 length files in the above list. Then reopen R (or RStudio) and reinstall the deleted packages.
You should now be able to list the packages again.
Chunxiao Xu's original suggestion above lists ALL of the R package directories. But the exact locations of these directories will vary from installation to installation, and their addresses will have to be edited for your installation.
Larry Hunsicker
Something simple to try: if it is an .rda file use load instead of readRDS. You can then save the loaded file as an .rds and try readRDS again.
Here is what I had to do to solve this error:
Open your Rstudio, go to install tab under packages
Note your install to library path.(where your package will be saved)
Go to the install library path.And hard delete the recent packages
Refresh you package details in Rstudio
This happened to me after I had to reboot my machine in the middle of installing several R packages. I removed the latest installed packages by physically removing the files in the appropriate library directory, reinstalled them, and all was well. I also had to remove a 00LOCK directory in the library directory.
You might have some problem with R packages .
See if the problem has occurred after you installed some packed or did you copied the packages.
What you can do is Copy all the packages from Library and save it somewhere, then Copy some packages on the Library and restart the R test it and see how it works you have to try with all the packages one by one .
I has the same issue and it was due to package problem.
I also had several problems opening an .RDS file, either "error reading from connection" or "unknown input format". I tried with several R versions, with version 3.4.2. the following worked:
(I accidentally uninstalled rstudio and installed it again, also installed older R version 3.4.2, I don't know if that changes anything)
set up a new working directory
I opened the RDS file directly instead of downloading it (so only saved to temp files), then I was able to open it in R
I moved it from temp files to my new working directory and used the Data_Essay_Account <- readRDS("C:/.../newdirectory/Data_Essay_Account.RDS") command and it worked.
Somehow properly downloading it and then moving it did not work, only after I had it in the temp files. Hard deleting packages did not work for me as I tried that initially.
Unlike the top few answers here, my issue was resolved not by doing anything with my installation of RStudio or cleaning local files, but by re-writing the RDS file.
I could confirm this because the file was stored in the cloud, and reading it from a variety of windows and mac laptops all failed, but similar RDS files from the same S3 bucket worked without a problem.
When I re-wrote the RDS file, the problem went away.
I checked for this issue on several forums and then I tried this and it worked for me:
1) Remove the ggplot2 package first
remove.packages("ggplot2")
2) Then Install the package again
install.packages("ggplot2")
3) restart rstudio and install your package again, hope this helps
Seems that the issue was with the required package (ggplot2 in my case) got corrupt and was hampering the installation of any new dependent package.
I had the same problem as the OP, but in my case the problem .rds files were not 0 bytes but had file size >0 and were full of NULL characters (at least that's what I saw when I opened them in Notepad++)
By using debugonce(loadNamespace) before loading the library that was giving me the error (in my example it was the VIM package) I eventually traced my problem to corrupted .rds files in the META folder of the forcats package, which was installed as a 5th generation import when I installed VIM
(In the rstudio environment pane)
__NamesSpacesLoading__ chr[1:5] "forcats" "haven" "rio" "car" "VIM"
I then fixed by VIM problem simply by removing and reinstalling forcats
Adapting the code in #csgillespie accepted answer, I could have found this by trying to read all the rds files as below
paths = .libPaths()
l <- list.files(paths,
pattern = "*\\.rds$",
ignore.case = T,
recursive = T,
full.names = TRUE)
checkRDS <- function(file) {
tryCatch({
readRDS(file)
"OK"
},
error = function(cond) {
return("Error")
})
}
l[sapply(l,checkRDS)=="Error"]
I was able to fix it by using .libPaths() and finding the 4.1 folder (my version of R was 4.1, so may differ). From there I closed R studio and deleted all the folders for each package.
I reinstalled all packages and found the packages which wouldn't download through the error messages. When I located the packages that didn't download I installed them by using: install.packages("package", type = "binary").
A bit long but solved all my issues.
My mirror was misconfigured. My mirror is Oregon State University because that is what I am closest too. Here is a list of mirrors. Call this code before installing any packages. More information in ?options.
mirror <- "https://ftp.osuosl.org/pub/cran/"
local({
r <- getOption("repos")
r["CRAN"] <- mirror
options(repos = r)
})
The workaround
Execute this command in the R console:
options(pkgType = "source")
You're good to go.

Resources