Error while using transformation function in R - r

I was working with baby names data set and encountered below error while using transform function. Any guidance/suggestion would be highly appreciated. I did reinstalled the packages but of no avail.
Mac OS X (Mountain Lion)
R version 3.1.2 (2014-10-31) -- "Pumpkin Helmet"
library(stringr)
require(stringr)
bnames1 <- transform(bnames1,
first = tolower(str_sub(name,1,1)),
last = tolower(str_sub(name,-1,1)),
vowels = vowels(name),
length= nchar(name),
per1000 = 10000 * prop,
one_par = 1/prop
)
Error in tolower(str_sub(name, 1, 1)) :
lazy-load database '/Library/Frameworks/R.framework/Versions/3.1/Resources/library/stringr/R/stringr.rdb' is corrupt
In addition: Warning messages:
1: In tolower(str_sub(name, 1, 1)) :
restarting interrupted promise evaluation
2: In tolower(str_sub(name, 1, 1)) : internal error -3 in R_decompress1

internal error -3 is often a functioning of installing on top of a loaded package. Restart R and restart your application. There may be other issues, but until you do this you won't be going much further.

Try
remove.packages("stringr")
install.packages("stringr")

Related

Suppress warnings in testthat functions introduces error

I have a function in my package that uses tryCatch for condition handling.
f <- function(){
tryCatch(expr = warning("?!"), error = function(c) {message(c); 3},
warning = function(c) {message(c); 4})
}
When I try to write a unit test for this with testthat, I always get an error related to restart or muffleWarning. Any idea how to solve this? I want to match output to 4 during warning, in this case.
test_that("test_f", {
suppressWarnings(output <- f())
expect_equal(output, 4)
})
> devtools::test()
error: test_f
no 'restart' 'muffleWarning' found
Backtrace:
1. base::suppressWarnings(output <- f()) tests/testthat/test_file.R:27:2
14. base::invokeRestart("muffleWarning")
version R version 3.6.3 (2020-02-29)
os Ubuntu 16.04.6 LTS
system x86_64, linux-gnu
testthat * 2.3.2

edit() crashes R on Mac OS X when trying to edit data frame

Does anybody have an idea for what I need to reconfigure?
I'm on Mac OS X Version 9.0 (10601.1.56.2) and R version 3.2.2
The edit() function seems to work for simple objects and functions
R segfaults if I try editing a data frame however
R version 3.2.2 (2015-08-14) -- "Fire Safety"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin13.4.0 (64-bit)
[R.app GUI 1.66 (6996) x86_64-apple-darwin13.4.0]
> x <- rnorm(10)
> edit(x)
[1] 0.96793711 0.46449359 0.05136297 0.38438847 0.73942230 -1.12691486 -0.84414357 -3.67522840 -1.03864446
[10] -0.37159107
> x <- data.frame(x)
> edit(x)
*** caught segfault ***
address 0x10db0, cause 'memory not mapped'
Traceback:
1: as.matrix.data.frame(format.data.frame(x, digits = digits, na.encode = FALSE))
2: as.matrix(format.data.frame(x, digits = digits, na.encode = FALSE))
3: print.data.frame(x)
4: function (x, ...) UseMethod("print")(x)
Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace
Selection:

R - Testing an installation

I am new to R. I have just installed R 3.2.2, and RStudio 0.99, under Windows 8.
As per section 3.2 Testing an Installation of Help contents,
I meant to execute the following 5 lines of commands.
Sys.setenv(LC_COLLATE = "C", LANGUAGE = "en")
library("tools")
testInstalledBasic("both")
testInstalledPackages(scope = "base", errorsAreFatal = FALSE)
testInstalledPackages(scope = "recommended", errorsAreFatal = FALSE)
The first 2 worked fine. The third threw an error, as shown here
> Sys.setenv(LC_COLLATE = "C", LANGUAGE = "en")
> library("tools")
> testInstalledBasic("both")
running strict specific tests
running code in ‘eval-etc.R’
unable to open output file
FAILED
[1] 1
Warning message:
running command '"C:/PROGRA~1/R/R-32~1.2/bin/x64/R" CMD BATCH --vanilla --no-timing "eval-etc.R" "eval-etc.Rout"' had status 2
>
What is the problem?
Could it be related to setting directories/permissions?
You seem to be missing the diff file from Rtools in the test folder. Simply copying/pasting should do the trick.

Error thrown within ddply crashes R

I'm running into an issue where plyr consistently crashes when an error is thrown from the supplied function
> require(plyr)
Loading required package: plyr
Warning message:
package ‘plyr’ was built under R version 3.0.2
> df <- data.frame(group=c("A","A","B","B"), num=c(11,22,33,44))
> ddply(df, .(group), function(x) {x})
group num
1 A 11
2 A 22
3 B 33
4 B 44
> ddply(df, .(group), function(x) {stop("badness")})
called from: (function ()
{
.rs.breakOnError(TRUE)
})()
Error in .fun(piece, ...) : badness
Browse[1]>
# Crashes immediately
Is anyone aware of why this may be occuring and how to prevent it (other than avoiding errors of course)?
(I'm running R 3.0.1 on platform: i386-w64-mingw32/i386 (32-bit) through RStudio 0.98.274 under Windows 7)
EDIT
As a workaround, I am redirecting any errors as warnings which avoids the crashes
ddply(df, .(group), function(x) tryCatch(stop("badness"), error = function(e) warning(e)) )
Will report what happens here if I manage to align the plyr and R versions.
I got the same issue on R 3.1.1 and plyr 1.8.1.
To fix it, I just reinstalled the package from source.
install.packages("plyr", type = "source")

Help with odd plyr/doSMP warning

I am trying to run the example for doSMP posted here:
require(plyr) # make sure you have 1.2 or later installed
x <- seq_len(20)
wait <- function(i) Sys.sleep(0.1)
system.time(llply(x, wait))
require(doSMP)
workers <- startWorkers(2) # My computer has 2 cores
registerDoSMP(workers)
system.time(llply(x, wait, .parallel = TRUE))
and I get the following warnings:
Warning messages:
1: <anonymous>: ... may be used in an incorrect context: ‘.fun(piece, ...)’
2: <anonymous>: ... may be used in an incorrect context: ‘.fun(piece, ...)’
What do these warnings mean, and should I worry about them?
edit:
getRversion() = 2.12.2
packageDescription("plyr", fields="Version") = 1.4
packageDescription("doSMP", fields="Version") = 1.0-1
Are you using windows?
I get the same error on linux.
And also the same error with doSNOW.
Then I tried with doMC instead of doSMP and it worked fine.

Resources