Skip to content
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

Merged
merged 2 commits into from
May 5, 2023

Conversation

nmouquet
Copy link
Contributor

@nmouquet nmouquet commented May 5, 2023

I am freaking out ...

@codecov
Copy link

codecov bot commented May 5, 2023

Codecov Report

Patch coverage has no change and project coverage change: -5.23 ⚠️

Comparison is base (0414d42) 41.05% compared to head (1689ec6) 35.83%.

❗ Current head 1689ec6 differs from pull request most recent head 8485881. Consider uploading reports for the commit 8485881 to get more accurate results

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     
Impacted Files Coverage Δ
R/plot_2d_img.R 0.00% <0.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

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)
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done !

Copy link
Member

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%)
Copy link
Member

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

Copy link
Contributor Author

@nmouquet nmouquet May 5, 2023

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 !

Copy link
Member

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))
Copy link
Member

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(...)

Copy link
Member

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))

Copy link
Contributor Author

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 ?

Copy link
Member

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)
}

Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx !

@ahasverus
Copy link
Member

Perfect, thx for answering the issues!

@ahasverus ahasverus merged commit 4a3bb6b into FRBCesab:main May 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants