Everything you never wanted to know about the R vulnerability
...but shouldn't be afraid to ask
https://aitap.github.io/2024/05/02/unserialize.html
This site is to serve as my note-book and to effectively communicate with my students and collaborators. Every now and then, a blog may be of interest to other researchers or teachers. Views in this blog are my own. All rights of research results and findings on this blog are reserved. See also http://youtube.com/c/hongqin @hongqin
https://aitap.github.io/2024/05/02/unserialize.html
R-bitrary Code Execution: Vulnerability in R’s Deserialization
https://hiddenlayer.com/innovation-hub/r-bitrary-code-execution/
tried reinstall R and packages
https://stackoverflow.com/questions/49190251/caught-segfault-memory-not-mapped-error-in-r
=> Try to install gganimate in CoLab, it is unavailable.
=> try in RStudio,
File access error:
Warning: file_renderer failed to copy frames to the destination directory
file_renderer(dir = ".", prefix = "gganim_plot", overwrite = FALSE)
The frame sources:
/var/folders/bw/k6_tkc2142v1wh5r_1yhkqhc0000gp/T//RtmpIopU0P/1eec3399c50d/gganim_plot0001.png
I tried to change file permission in Finder, but my username is not allowed.
The following codes worked:
I tested and found out that I have ffmpeg installed.
Reference:
https://ottverse.com/create-video-from-images-using-ffmpeg/
https://github.com/zonination/perceptions
The rnorm_multi()
function makes multiple normally distributed vectors with specified parameters and relationships.
https://cran.r-project.org/web/packages/faux/vignettes/rnorm_multi.html
https://jokergoo.github.io/ComplexHeatmap-reference/book/index.html
https://jokergoo.github.io/ComplexHeatmap-reference/book/a-single-heatmap.html#colors
https://fronkonstin.com/2018/09/06/tweetable-mathematical-art-with-r/
Ready 4 R
https://ready4r.netlify.app/schedule/
tryCatch( info <- getMeta(lat = metaTb$Lat[i], lon = metaTb$Long_[i], plot=FALSE),
error=function(e) {
print( paste( "*** tryCaught error:", metaTb[i, ]) )
}
)
print(i)
# Hong will install anaconda R403 in a conda environment on ts117. This strategy worked.
conda create --name condaR403
environment location: /home/hqin/.conda/envs/condaR403
-bash-4.2$ conda activate condaR403
conda install -c r r-base #??
# which R shows an R403 inside an conda environment.
R
install.packages('tidyverse') #this seems worked.
install.packages('EpiNow2') #this run for a while
non-zero exit again due to V8.
(condaR403) -bash-4.2$ conda install -c conda-forge libv8
$ conda install -c conda-forge r-randomcolor
R
install.packages('EpiNow2') #this worked!!!!
> library(EpiNow2)
>
module load sge
qsub epinow2.pbs #this runs!!!!
(condaR403) -bash-4.2$ cat epinow2.pbs
#!/bin/bash -l
#$ -S /bin/bash
#$ -N epinow_job
#$ -V
#$ -cwd
. /etc/profile.d/modules.sh
module load anaconda/5.2.0
source activate condaR403
R -f batch_Rt_by_county.R --args 900 901 1 4/1/2020 5/1/2020
# THIS DID NOT WORK
-bash-4.2$ module load anaconda/5.2.0
-bash-4.2$ conda create --name tsR403
Collecting package metadata: done
Solving environment: done
## Package Plan ##
environment location: /home/hqin/.conda/envs/tsR403
Proceed ([y]/n)? y
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
# $ conda activate tsR403
#
# To deactivate an active environment, use
#
# $ conda deactivate
-bash-4.2$
-bash-4.2$ conda activate tsR403
(tsR403) -bash-4.2$ conda install -c conda-forge libv8
Collecting package metadata: done
Hong then run R
install.packages('tidyverse') #this seem to worked.
-----------------------------[ ANTICONF ]-------------------------------
Configuration failed to find the libv8 engine library. Try installing:
* deb: libv8-dev or libnode-dev (Debian / Ubuntu)
* rpm: v8-devel (Fedora, EPEL)
* brew: v8 (OSX)
* csw: libv8_dev (Solaris)
To use a custom libv8, set INCLUDE_DIR and LIB_DIR manually via:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
---------------------------[ ERROR MESSAGE ]----------------------------
<stdin>:1:16: fatal error: v8.h: No such file or directory
compilation terminated.
-------------------------------------------------------
(tsR403) -bash-4.2$ conda install -c conda-forge r-randomcolor
Collecting package metadata: \
#this install many packages
Ref: https://github.com/iaconogi/bigSCale2/issues/19
I then tried:
R: install.packages('EpiNow2') #this seems to be running now.
library(EpiNow2) #it worked!
install.packages('woldmet')
#The entire install seem to take almost 2 hours.
Checked a few hour later, EpiNow2 installation did not work.
see:
https://askubuntu.com/questions/1237102/problem-installing-r-4-0-on-ubuntu-18-04
sudo apt remove r-base
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran40/'
sudo apt update
sudo apt install r-base
# Count the number of full duplicates
sum(duplicated(bike_share_rides))
# Remove duplicates
bike_share_rides_unique <- distinct(bike_share_rides)
# Count the full duplicates in bike_share_rides_unique
sum(duplicated(bike_share_rides_unique))
# Find duplicated ride_ids
bike_share_rides %>%
count(ride_id) %>%
filter(n > 1)
# Remove full and partial duplicates
bike_share_rides_unique <- bike_share_rides %>%
# Only based on ride_id instead of all cols
distinct(ride_id, .keep_all = TRUE)
bike_share_rides %>%
# Group by ride_id and date
group_by(ride_id, date) %>%
# Add duration_min_avg column
mutate(duration_min_avg = mean(duration_min)) %>%
# Remove duplicates based on ride_id and date, keep all cols
distinct(ride_id, date, .keep_all = TRUE) %>%
# Remove duration_min column
select(-duration_min)
# Find bad dest_size rows
sfo_survey %>%
# Join with dest_sizes data frame to get bad dest_size rows
anti_join(dest_sizes, by = "dest_size") %>%
# Select id, airline, destination, and dest_size cols
select(id, airline, destination, dest_size)
# Add new columns to sfo_survey
sfo_survey <- sfo_survey %>%
# dest_size_trimmed: dest_size without whitespace
mutate(dest_size_trimmed = str_trim(dest_size),
# cleanliness_lower: cleanliness converted to lowercase
cleanliness_lower = str_to_lower(cleanliness))
# Count values of dest_size_trimmed
sfo_survey %>%
count(dest_size_trimmed)
# Count values of cleanliness_lower
sfo_survey %>%
count(cleanliness_lower)
# Count categories of dest_region
sfo_survey %>%
count(dest_region)
# Categories to map to Europe
europe_categories <- c("EU", "eur", "Europ")
# Add a new col dest_region_collapsed
sfo_survey %>%
# Map all categories in europe_categories to Europe
mutate(dest_region_collapsed = fct_collapse(dest_region,
Europe = europe_categories)) %>%
# Count categories of dest_region_collapsed
count(dest_region_collapsed)
sfo_survey %>%
filter(str_detect(phone, "-"))
- 1
, for example formula = response ~ intercept - 1
.
format(Sys.time(), "%a %b %d %H:%M:%S %Y")
format(Sys.time(), "%Y%b%d_%H%M%S")
#regular expression
require(org.Sc.sgd.db) x <- org.Sc.sgdALIAS ls(x)[grep("^Y..\\d{3}", ls(x))]
http://www.regular-expressions.info/rlanguage.html
! x x & y x && y x | y x || y xor(x, y)
rm(list=ls() ); unlist(strsplit("a.b.c", "\\.")) ----- str(x) attributes(x) -------------- outer( month.abb, 1999:2003, FUn="paster"); Letters <- c( LETTERS, letters); Letters[ ! sapply(Letters, function(xx) exists(xx) ) ]; # anonymous function as a wrapper for a primitive function ------------ legend(100,60, seq(100,200,1), lty=1) # line legends Library(MASS); example(Skye); #tenary plot library(help = survivial) ColorBrewer.org useful comnds: x11; factor; relevel; class; loess; contour; is.element; math %in%; grep; sample; nrow; grepmisc: hist2d url() --- class and object CA@a[1] ---- test1 <- list( time= c(4, 3,1,1,2,2,3), status=c(1,NA,1,0,1,1,0), x= c(0, 2,1,1,1,0,0), sex= c(0, 0,0,0,1,1,1)) coxph( Surv(time, status) ~ x + strata(sex), test1) #stratified model ---- delete NA form matrix > x<-matrix(1:16,4,4) > x[col(x)>=row(x)]<-NA > x[,! apply(x,2,function(x) all(is.na(x))) ] [,1] [,2] [,3] [1,] NA NA NA [2,] 2 NA NA [3,] 3 7 NA [4,] 4 8 12 ---- ? R/Splus Perl interface RSperl ? R Pythong interface Rpy Rpython not in CRAN ---- date.grouping <- function(d) { # for ea date in d calculate date beginning 6 month period which contains it mat <- matrix(as.numeric(unlist(strsplit(as.character(d),"-"))),nr=2) f <- function(x) do.call( "ISOdate", as.list(x) ) POSIXct.dates <- apply(rbind(mat,1),2,f) + ISOdate(1970,1,1) breaks <- c(seq(from=min(POSIXct.dates), to=max(POSIXct.dates), by="6 mo"), Inf) format( as.POSIXct( cut( POSIXct.dates, breaks, include.lowest=T )), "%Y-%m" ) } ---- nonlinear regression library(nls) ---- http://www.bioconductor.org/ ---- library(lattice) ---- persp() ---- las=1 or 2 You can use the graphics parameter "srt" to rotate displayed text by a specified number of degrees, e.g. srt=45 to put it on an angle, srt=90 to put it vertical. ---- cnams = dimnames(aa)[[2]] cnams[which(cnams == 'blah3.Mg')] = 'Mg (%)' ... dimnames(aa)[[2]] = cnams ---- eval(substitute(lf <- locfit(~s, data=age), list(s=s))) ------ sub=sort(sample(x,200, replace=F)) postscript("try.ps") matplot(x[sub],y[sub,],type="l",lwd=5) dev.off() -----
>Does anyone know if R has the functionality to calculate a simple
>moving average. I cant seem to find it in the help menu.
filter in library ts. does filter() do what you need?
Or look at the 'running' function in the gregmisc package.
moving.average <-
function(x, k) {
n <- length(x)
y <- rep(0, n)
for (i in (1+k):n)
y[i] <- mean(x[(i-k):i])
return(y)
}
----
tree packages
----
# Create an Example Data Frame Containing Car x Color data, with long car names
carnames <- c("BMW: High End, German",
"Renault: Medium End, French",
"Mercedes: High End, German",
"Seat: Imaginary, Unknown Producer")
carcolors <- c("red","white","silver","green")
datavals <- round(rnorm(16, mean=100, sd=60),1)
data <- data.frame(Car=rep(carnames,4),
Color=rep(carcolors, c(4,4,4,4) ),
Value=datavals )
# generate balloon plot with default scaling, the column labels will overlap
# balloonplot( data$Color, data$Car, data$Value)
# try again, with column labels rodated 90 degrees, and given more space
balloonplot( data$Car, data$Color, data$Value, colmar=3, colsrt=90)
----
Here is a very rough addlogo() using pixmap:
"addlogo" <- function(x, y, pixmap) {
if (is.list(x)) {
y <- x$y
x <- x$x
}
else if (missing(y))
stop("missing y")
if (!is.numeric(x) || !is.numeric(y))
stop("non-numeric coordinates")
if ((nx <- length(x)) <= 1 || nx != length(y) || nx > 2)
stop("invalid coordinate lengths")
pixmap@bbox[1] <- x[1]
pixmap@bbox[2] <- y[1]
pixmap@bbox[3] <- x[2]
pixmap@bbox[4] <- y[2]
pixmap@cellres[1] <- (pixmap@bbox[3] - pixmap@bbox[1]) / pixmap@size[2]
pixmap@cellres[2] <- (pixmap@bbox[4] - pixmap@bbox[2]) / pixmap@size[1]
plot(pixmap, add=TRUE)
invisible(pixmap)
}
which will work with locator() too. To maintain aspect, it shouldn't alter
the relative cell resolutions, and should just use the new x or y, bur
this is the general case. The handling of the location of the logo is
copied & pasted from legend().
----
x <- readLines(myfile)
strsplit(substring(x,8),split="")
----