-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
new function plot_2d_img ... hope it will please you master ! #4
Conversation
Codecov ReportPatch coverage has no change and project coverage change:
Additional details and impacted files@@ Coverage Diff @@
## main #4 +/- ##
==========================================
- Coverage 41.05% 35.83% -5.23%
==========================================
Files 10 11 +1
Lines 151 173 +22
==========================================
Hits 62 62
- Misses 89 111 +22
☔ View full report in Codecov by Sentry. |
R/plot_2d_img.R
Outdated
#' set.seed(3) | ||
#' df <- cbind.data.frame(x=runif(10, 0, 10),y=runif(10, 0, 10),img_names=lessR::to("img_", 10)) | ||
#' pathimages <- system.file("extdata", "plot2dimg", package = "rutils") | ||
#' plot_2d_img <- function(df,scale=0.2,size=-35L,pathimages,cexaxis=1.5, cexlab=2.5,lm=TRUE,xR=1.5,yR=10,colR="gray",cexR=1.5,colline="gray",lwline=2,ltyline=2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see a typo: can you please remove <- function
in this line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this fix, all the checks will pass ;)
R/plot_2d_img.R
Outdated
#' | ||
#' @param df a `data.frame` with three colums x coord,y coord,img_names | ||
#' @param scale a numeric between 0 and 1 (used to resize the images) | ||
#' @param size the parameter size of the function imager::resize (between -0L and -100L) used to reduce the resolution of the image (proportion between 0 and 100%) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please write your code to avoid exceeding 80 characters horizontally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes master ! It's a bit psychorigid but I'll go along with it... can you build a function that does this automatically ? hahahahah !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want, there is an R package formatR and an RStudio addin ;)
R/plot_2d_img.R
Outdated
miny <- min(na.omit(df[,2])) | ||
maxy <- max(na.omit(df[,2]))*1.2 | ||
|
||
par(mar=c(8, 9, 4.1, 2.1),mgp=c(6,2,0)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not recommended to modify global options. Before doing this, you have to store user options and to reset it at the end of the function. You can use this code:
opar <- par(no.readonly = TRUE)
on.exit(par(opar))
par(...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition, I would add an ellipsis argument to your function (...
) to pass to the par()
function.
For instance:
plot_2d_img <- function(df, ...)
par(...)
Later, when you call your function, you can do: plot_2d_img(data, mar = c(8, 9, 4.1, 2.1), mgp = c(6, 2, 0))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if I add an ellipsis argument, this means that I don't need to store user options as suggest above ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, you still have to store these values in opar
and restore it with the on.exit()
. Note that the function on.exit()
must be used before modifying the par() options. This is really GOOD practice recommended by the CRAN.
mods <- summary(lm(reformulate("x","y"), data = df)) | ||
text(x=xR, y=yR, paste0("r2= ",round(mods$r.squared,2)),cex=cexR,adj=0,col=colR) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As your function does not return anything, add this final line: invisible(NULL)
If you do not assign this function, nothing is printed, otherwise, it returns NULL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx !
Perfect, thx for answering the issues! |
I am freaking out ...