rWishart function not found in R - r

I am using R version 2.13.1 (2011-07-08) on Windows 7 and wish to use the function rWishart.
When I enter, say, rWishart(1,2,3), I get
Error: could not find function "rWishart"
Entering just rWishart, however, displays a matrix:
[,1] [,2]
[1,] 1 0
[2,] 0 1
To check that this object is not interfering with the function, I did rm(rWishart), and now rWishart gives
Error: object 'rWishart' not found"
but I still get the function-not-found error when using it as a function.
A search of my hard drive finds no rWishart.* file. I Googled and downloaded an rWishart.R file from
https://projects.cs.kent.ac.uk/projects/cxxr/svn/branches/sqlite/src/library/stats/R/
to the directory shown by getwd().
When I did load("<DIRECTORY>/rWishart.R") , I got
Error: bad restore file magic number (file may be corrupted) -- no data loaded
In addition: Warning message:
file 'rWishart.R' has magic number '# Fi'
Use of save versions prior to 2 is deprecated
Would someone be able to tell me how I can get the rWishart function running?

rWishart wasn't introduced in base R until 2.15. So you should update your version of R or find a package that adds the functionality.

Related

Problem with loading .RData objects: "file ‘pathway.path.RData’ has magic number '' Use of save versions prior to 2 is deprecated"

I am trying to load an .RData file downloaded from the github repository https://github.com/VCCRI/SPAGI/tree/master/data.
After having saved the files on my computer if I try to load one of them with
load("./data/pathwaypath.RData")
I get the error message:
Warning message:
“file ‘pathwaypath.RData’ has magic number ''
Use of save versions prior to 2 is deprecated”
Error in load("./data/pathwaypath.RData"): bad restore file magic number (file may be corrupted) -- no data loaded
Traceback:
1. load("./data/pathwaypath.RData")
It also does not work with readRDS:
readRDS("./data/pathwaypath.RData")
throws
Error in readRDS("./data/pathwaypath.RData"): unknown input format
Traceback:
1. readRDS("./data/pathwaypath.RData")
Browsing through stackoverflow I gained the sense that it might be a problem with the serialization protocol used for creating the .RData object. Would anyone know more about it? Are there any known solutions to this issue?
I am running R version 4.0.0 (2020-04-24).
Here's an approach that is working for me on version 3.6.3:
temp <- tempfile()
download.file("https://github.com/VCCRI/SPAGI/blob/master/data/pathway.path.RData?raw=true",temp)
load(temp)
pathway.path[[1]][1:3]
#[[1]]
#[1] "RTN4R" "NGFR" "IRAK1" "MAP3K7" "IKBKB" "NFKB1"
#
#[[2]]
#[1] "RTN4R" "NGFR" "IRAK1" "MAP3K7" "IKBKB" "FOXO3"
#
#[[3]]
#[1] "RTN4R" "NGFR" "MAPK8" "JUN"

runjags trouble locating JAGS - error "'where' not found" even after setting jagspath

Seems that runjags suddenly (after update to version 2.0.3-2) has trouble finding JAGS binary, issuing an error:
[1] "Error in system(\"where jags\", intern = TRUE) : 'where' not found\n"
attr(,"class")
[1] "try-error"
attr(,"condition")
<simpleError in system("where jags", intern = TRUE): 'where' not found
I fixed this by putting this line to my Rprofile:
.runjags.options <- list(jagspath = "c:/Program Files/JAGS/JAGS-4.2.0/i386/bin/jags-terminal.exe")
This pretty much fixes the problem (although it is not ideal - previous versions of runjags could find the binary automatically).
However, when the Rgui (in Windows XP) is launched by opening an .Rdata file, which is associated to it, it stops working:
> .runjags.options # it was set in the Rprofile
$jagspath
[1] "c:/Program Files/JAGS/JAGS-4.2.0/i386/bin/jags-terminal.exe"
> require(runjags)
Loading required package: runjags
Warning message:
package ‘runjags’ was built under R version 3.1.3
> runjags.getOption("jagspath")
[1] "Error in system(\"where jags\", intern = TRUE) : 'where' not found\n"
attr(,"class")
[1] "try-error"
attr(,"condition")
<simpleError in system("where jags", intern = TRUE): 'where' not found
Is this a bug? How to fix this?
I am currently calling runjags.options(jagspath = "c:/Program Files/JAGS/JAGS-4.2.0/i386/bin/jags-terminal.exe") in my source after require(runjags), but I would like to avoid this as much as possible!
The problem is in the findjags() function, more specifically use of the 'where' system command which was added to Windows in 2003 and therefore doesn't exist in Windows XP. There is some code in findjags() that is designed to detect earlier versions of Windows and revert to a different method of finding JAGS, but this hasn't changed since version 1.x so I don't know why this has 'suddenly' stopped working. Perhaps there has been a change in your system, or a change in the way the system() command works in R. I have modified this code to work around where I think the error is coming from, but I don't have access to Windows XP (I'm rather surprised that you do!) so I can't test it. I don't think it will do any harm though so I will include it in the next release anyway, after testing on more recent versions of Windows.
I also don't know exactly why the .runjags.options is not being found when you open a .Rdata file, but it is possible that opening a .Rdata file loads the library before setting objects. I will look into this but it is likely not something I can do anything about. The alternative to using runjags.options() is to set the jags argument in calls to run.jags etc.

R package 'biomod2' cannot find file when executing plot function

I am attempting to use the plot() function in the biomod2 package, following a vignette here (http://finzi.psych.upenn.edu/usr/share/doc/library/biomod2/doc/Simple_species_modelling.pdf). Below is the error I am getting:
getwd()
# [1] "/home/gjanzen/Documents/Hufford/Drought/Data/Layers"
plot(myBiomodData)
Error in getExportedValue(pkg, name) : cannot open file
'~/R/x86_64-pc-linux-gnu-library/3.3/viridisLite/data/Rdata.rdb': No
such file or directory In addition: Warning message: In
getExportedValue(pkg, name) : restarting interrupted promise
evaluation
I have confirmed that the Rdata.rdb exists, in the following directory:
f <- file.choose()
f
# [1] "/home/gjanzen/R/x86_64-pc-linux-gnu-library/3.3/viridisLite/data/Rdata.rdb"
So, to me, it looks like the plot() function is looking in the wrong place. How can I change where this function looks for Rdata.rdb? Can I alter the path somehow? Or would changing my working directory fix this?
PS - This is my first post on Stack Overflow, so please forgive any mistakes in etiquette, and/or feel free to point them out to me so that I do not repeat them.
I think that the first thing to try is to reinstall the package viridisLite that seems to be the one that is causing troubles.
install.packages('viridisLite', dep = TRUE)
If this not solves the issue you should try to open a new plotting device threw x11() to check if the issue is not coming from the R (resp. RStudio) plotting device itself.

"bad restore file magic number" error in R

As in What could cause a "bad magic number" error when loading an R workspace and how to avoid it? and R has magic number 'ëPNG' error, I'm getting a bad restore file magic number error:
> load("fossilien.dat")
Error: bad restore file magic number (file may be corrupted) -- no data loaded
In addition: Warning message:
file ‘fossilien.dat’ has magic number '"Samp'
Use of save versions prior to 2 is deprecated
Using the source function gives me a different error (similar to unexpected string constant):
> source("fossilien.dat")
Error in source("fossilien.dat") :
fossilien.dat:1:10: unexpected string constant
1: "Sample" "Sname"
^
This is especially frustrating as I'm confident the source of data is legit - its for a homework problem: ftp://stat.ethz.ch/Teaching/Datasets/WBL/fossilien.dat
None of the SO questions above were really answered properly so I thought I would try again.
Some details about my R installation:
> R.Version()
$platform
[1] "x86_64-apple-darwin9.8.0"
$version.string
[1] "R version 2.15.3 (2013-03-01)"
The read.table function ended up working: http://stat.ethz.ch/R-manual/R-devel/library/utils/html/read.table.html
> fossildata <- read.table("fossilien.dat")
EDIT by CGW: load is for files in .rdata format, while your fossilien.dat clearly is an ASCII table. source executes the named file or object.

Creating a help file for a vector object

I'm working in R Version 2.15.0 on Mac OS X (Intel, 64-bit). When I apply prompt to a vector object, it throws an error unless I specify the file argument. Additionally, when I do provide a file name, there are oddities in the help file skeleton (e.g. many \name, \alias, and \usage commands, one for each element of the vector). Are these the expected results of prompt when specifying a vector? Sample commands that replicate the problem:
> COL <- rgb(1:4 / 4, 4:1 / 4, c(1, 0, 1, 0))
> prompt(COL)
Error in file(file, ifelse(append, "a", "w")) :
invalid 'description' argument
In addition: Warning messages:
1: In if (is.na(filename)) return(Rdtxt) :
the condition has length > 1 and only the first element will be used
2: In if (file == "") file <- stdout() else if (substring(file, 1L, :
the condition has length > 1 and only the first element will be used
3: In if (substring(file, 1L, 1L) == "|") { :
the condition has length > 1 and only the first element will be used
> prompt(COL, file="COL.Rd")
Created file named ‘COL.Rd’.
Edit the file and move it to the appropriate directory.
One other odd component: when running 32-bit R on my machine and loading in the package, R will not properly load and allow access to the vector object when it is from the package (i.e. it throws an error: Error: internal error -3 in R_decompress1). However, when I load in the .rda object directly, things are fine in R 32-bit. Are such problems/inconsistencies expected when running R 32-bit on a 64-bit machine?
Edit: One more question. Any idea on how to get .R and .rda files to open in R 64-bit by default? The "Get Info" trick doesn't work... when clicking "Change All", it reverts back to the default R 32-bit. This seems to be a problem for certain file types.
Thanks!
As Paul said, split your questions next time.
Regarding the prompt function:
If you don't specify anthing, the filename is set to NULL, and the default behaviour is that the object itself is used to create a filename. When you pass a vector, the function sees that as a vector of objects and hence creates a vector of names. That gives the error message.
If you want to document a vector object, use the argument name instead, eg: prompt(name="COL"). That will give you the wanted behaviour
If you want to see a list, ?prompt tells you that you should specify filename=NA. The output will come to the console instead.
Opening .R and .rda files by 64 bit by default is OS dependent. In Windows you can do this eg via the control Panel > Default Programs > set Associations and then set the association to the 64bit binary file of R (to be found in ...\R\R-2.15.0\bin\x64 ).
The second question is impossible to answer without further details. I suggest you figure out how to reproduce that (see this question) and ask it in a new question

Resources