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

Get rid of warnings and notes in R CMD check #338

Merged
merged 5 commits into from
Jul 22, 2022

Conversation

IndrajeetPatil
Copy link
Member

Closes #162

@codecov-commenter
Copy link

codecov-commenter commented Jul 18, 2022

Codecov Report

Merging #338 (af9bb6c) into develop (25f8fa9) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff            @@
##           develop     #338   +/-   ##
========================================
  Coverage    64.21%   64.21%           
========================================
  Files           50       50           
  Lines         2979     2979           
========================================
  Hits          1913     1913           
  Misses        1066     1066           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 25f8fa9...af9bb6c. Read the comment docs.

),
package = "tlf",
add = FALSE
)
Copy link
Member

Choose a reason for hiding this comment

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

I was trying to understand where those global varibales are defined - and failed.
E.g. "fillLength":

# fillLength defined in .parseUpdateAestheticProperty
fillValues <- .getAestheticValues(
n = fillLength,
selectionKey = plotConfiguration$ribbons$fill,
aesthetic = "fill"
)

The comment says "fillLength defined in .parseUpdateAestheticProperty" - but there is no such definition in .parseUpdateAestheticProperty - and also not elsewhere in the code.
.parseUpdateAestheticProperty <- function(aestheticProperty, plotConfigurationProperty) {
c(
parse(text = paste0(aestheticProperty, 'Variable <- gsub("`", "", mapLabels$', aestheticProperty, ")")),
parse(text = paste0(aestheticProperty, "Length <- length(unique(mapData[, ", aestheticProperty, "Variable]))")),
# Update the property using ggplot `scale` functions
parse(text = paste0(
"suppressMessages(plotObject <- plotObject + ggplot2::scale_", aestheticProperty, "_manual(",
"values=.getAestheticValues(n=", aestheticProperty, "Length,",
"selectionKey=plotConfiguration$", plotConfigurationProperty, "$", aestheticProperty,
',aesthetic = "', aestheticProperty, '")))'
)),
# remove the legend of aesthetic if default unmapped aesthetic
parse(text = paste0("if(isIncluded(", aestheticProperty, 'Variable, "legendLabels")){plotObject <- plotObject + ggplot2::guides(', aestheticProperty, " = 'none')}"))
)
}

I am very confused

Copy link
Member Author

@IndrajeetPatil IndrajeetPatil Jul 18, 2022

Choose a reason for hiding this comment

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

I think that comment is outdated.

As mentioned in this NOTE:

plotTimeProfile: no visible binding for global variable 'fillLength'

This unquoted symbol or name appears in the code, but it is not defined anywhere, and so R CMD Check complaints.

This is a common problem with non-standard evaluation, and I am using the standard solution.

Copy link
Member Author

Choose a reason for hiding this comment

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

For example,

df <- data.frame(x = 1, y = 2)

df[, "x"]

dplyr::select(df, x) # no visible binding for global variable 'x'

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

@Yuri05 Yuri05 Jul 18, 2022

Choose a reason for hiding this comment

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

Well, maybe it's just my very limited understanding of R, but I just don't get how you can use undefined variable? It must be defined somewhere, or not?

Where does the value of fillLength come from in the piece of code above?

Copy link
Member

Choose a reason for hiding this comment

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

ok, thx anyway.
@pchelle Can you explain?

Copy link
Member Author

Choose a reason for hiding this comment

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

IINM, he is on vacation this week.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry for the delay.
The variable fillLength is created during the call of .parseUpdateAestheticProperty when input argument is "fill"
To prevent potential copy/paste issues of very similar lines of code, most of the functions from aaa-utilities.R directly output R code as character strings (which are then transformed into expressions to be evaluated as actual R code using parse(text) and eval(expression).

Below shows the expression returned when the function .parseUpdateAestheticProperty is called with the arguments "fill" and ribbons.

> .parseUpdateAestheticProperty("fill", "ribbons")

expression(
fillVariable <- gsub("`", "", mapLabels$fill),
fillLength <- length(unique(mapData[, fillVariable])),
suppressMessages(
plotObject <- plotObject + ggplot2::scale_fill_manual(
values = .getAestheticValues(n = fillLength, selectionKey = plotConfiguration$ribbons$fill, aesthetic = "fill")
)
), 
if (isIncluded(fillVariable, "legendLabels")) {
plotObject <- plotObject + ggplot2::guides(fill = "none")
}
)

When the expression is wrapped by eval(), this code is evaluated and

  • Creates the variable fillVariable, column name in the data linked to the fill property
  • Creates the variable fillLength, number of unique values for the fill property (used for selecting the right number of colors)
  • Update the fill properties of the plot plotObject
  • Remove the legend if no mapping was actually defined

Note that changing "fill" by any other property name such as "color" or "alpha" would directly create an evaluated R code with all the property names changed to "color" or "alpha"

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the warning in R-CMD-Check is from the function plotTimeProfile which needs to manage between the aesthetic properties of errorbars, scatter points, ribbons and lines while potentially sharing the color aesthetic property.

The plotTimeProfile code was leveraging the creation of the fillLength property created by a previous call of .parseUpdateAestheticProperty to merge the fill property of both simulated and observed data.

Since there is no actual written code of fillLength <- length(unique(mapData[, fillVariable])) (because created and run from the expression), the check flags the variable fillLength as not being created before its use.

Copy link
Member

Choose a reason for hiding this comment

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

ok, now I at least understand how it works :)
I have further questions/thoughts regarding this, but I will create separate issues for that.
Accepting the PR for now.

@IndrajeetPatil IndrajeetPatil marked this pull request as draft July 18, 2022 13:33
@IndrajeetPatil IndrajeetPatil marked this pull request as ready for review July 22, 2022 14:59
@Yuri05 Yuri05 mentioned this pull request Jul 22, 2022
@IndrajeetPatil IndrajeetPatil merged commit cdcdd20 into develop Jul 22, 2022
@IndrajeetPatil IndrajeetPatil deleted the 162_get_rid_of_warnings branch July 22, 2022 16:57
@Yuri05 Yuri05 mentioned this pull request Jul 22, 2022
Yuri05 pushed a commit to Yuri05/TLF-Library that referenced this pull request Jan 27, 2023
msevestre added a commit that referenced this pull request Jan 27, 2023
* Version 1.4.89 (#323)

* Fixes #280 background elements defined a priori (#284)

This allows to switch off grid at creation of plot configuration

* Fixes #281 Fixes #282 update vignettes (#290)

* Fixes #289 update news (#291)

* 273 na rm (#278)

* Fixes #273 NA are removed without producing warnings

* Fixes #272 set transparency for molecular plots

* Update line layer in scatter plots

* Fix typo

Co-authored-by: Indrajeet Patil <patilindrajeet.science@gmail.com>

* Fixes #288 create sections in reference page of doc website (#292)

* Fixes #288 create sections in reference page of doc website

* Remove duplicated last reference section

* Export configuration output folder (#287)

* Add `path` property to `ExportConfiguration`

* Added argument `path` to `ExportConfiguration`
Documentation generated with roxygen2

* Run styler

* Fix wrong assignment of `path` property

* adopt same gitattributes as other R repos in OSP (#295)

* whitespace changes due to new gitattributes

* Improvements to the `PlotGridConfiguration` class (#293)

* Bump package version; update NEWS

* Also update website for new package version

* rest

* Update appveyor.yml

* Add print method for plot grid config

Closes #274

* document

* better example

* better headers

* add more aesthetic parameters for plot grid config

- Add needed enums
- Update NEWS for the same
- Update docs
- Add test
- Update examples

* style

* caption position

* bump version

* Add PlotAnnotationTextSize

* move enums to plot grid file

* docs

* Update PlotGridConfiguration.Rd

* needed for vdiffr tests

* move all enums to their own file

* also add watermark size to the enum (#297)

* whitespace changes due to new gitattributes

* Use utilities from ospsuite.utils (#299)

To be considered once Open-Systems-Pharmacology/OSPSuite.RUtils#115 is merged.

* Add `collate` directive (#296)

* Fixes #301 Helper function to get lines from fold distance values (#302)

* Fixes #301 Helper function to get lines from fold distance values

* Update news, doc and style

* Update NEWS.md

* Update NEWS.md

Co-authored-by: Indrajeet Patil <patilindrajeet.science@gmail.com>

* 262 res vs pred (#270)

* Fixes #262 update documentation of plotResVsPred

* Fixes #262 res vs time functions are aliases of res vs pred functions

Include plotResVsTime, ResVsTimePlotConfiguration and ResVsTimeDataMapping

* res vs time classes derive from res vs pred

As a consequence, they are not equal and can have different theme properties

* re-document

Co-authored-by: Indrajeet Patil <patilindrajeet.science@gmail.com>

* Fixes #304 add enum helper for ticklabels (#305)

* Fixes #304 add enum helper for ticklabels

* Fix typo in Pi label mapping

* Fix typo in example

* If ticklabels is of type expression, numeric or function use it as is

If expression or function isIncluded throw an error so the assertion is necessary before isIncluded

* style and document

Co-authored-by: Indrajeet Patil <patilindrajeet.science@gmail.com>

* Prepend internal function names with a dot (#307)

As per coding guidelines.

Update docs for these functions as well.

Closes #306

* 308 fold distance (#311)

* Fixes #313 Remove badges from Website-docu, update news (#314)

Co-authored-by: Yuri05 <Yuri05@github.com>

* Fixes #260 legend titles are updated and can be defined in themes (#315)

* Fixes #260 legend titles are updated and can be defined in themes

* Remove legend and legend title reset in boxplots

* Fixes #312 remove infinite values from plots (#316)

* fixes #318 Update website (#319)

Co-authored-by: Yuri05 <Yuri05@github.com>

* Fixes #320 Website: some images not displayed (#321)

Co-authored-by: Yuri05 <Yuri05@github.com>

* 320 attempt2 (#322)

* delete old docs folder

* Fixes #320 Website: some images not displayed

Co-authored-by: Yuri05 <Yuri05@github.com>

Co-authored-by: Pierre Chelle <45343665+pchelle@users.noreply.github.com>
Co-authored-by: Indrajeet Patil <patilindrajeet.science@gmail.com>
Co-authored-by: Pavel Balazki <pavel.balazki@gmail.com>
Co-authored-by: Yuri05 <Yuri05@github.com>

* Improvements to the `PlotGridConfiguration` class (#293)

* Bump package version; update NEWS

* Also update website for new package version

* rest

* Update appveyor.yml

* Add print method for plot grid config

Closes #274

* document

* better example

* better headers

* add more aesthetic parameters for plot grid config

- Add needed enums
- Update NEWS for the same
- Update docs
- Add test
- Update examples

* style

* caption position

* bump version

* Add PlotAnnotationTextSize

* move enums to plot grid file

* docs

* Update PlotGridConfiguration.Rd

* needed for vdiffr tests

* move all enums to their own file

* also add watermark size to the enum (#297)

* Fixes #301 Helper function to get lines from fold distance values (#302)

* Fixes #301 Helper function to get lines from fold distance values

* Update news, doc and style

* Update NEWS.md

* Update NEWS.md

Co-authored-by: Indrajeet Patil <patilindrajeet.science@gmail.com>

* Fixes #304 add enum helper for ticklabels (#305)

* Fixes #304 add enum helper for ticklabels

* Fix typo in Pi label mapping

* Fix typo in example

* If ticklabels is of type expression, numeric or function use it as is

If expression or function isIncluded throw an error so the assertion is necessary before isIncluded

* style and document

Co-authored-by: Indrajeet Patil <patilindrajeet.science@gmail.com>

* 308 fold distance (#311)

* 320 attempt2 (#322)

* delete old docs folder

* Fixes #320 Website: some images not displayed

Co-authored-by: Yuri05 <Yuri05@github.com>

* Fixes #325 legend title properties from argument title are used (#328)

Issue was caused because properties of R6 (Label object here) are linked if object is not cloned

* Fixes #327 horizontal bars for obs vs pred plots (#331)

- error is replaced in favor of ymin/ymax or xmin/xmax
- dataMapping initialize method needs to explicitly redefine `x` and `y` arguments because of R partial matching (if user inputs `x="a"`, partial matching would assign "a" to `xmin` instead of `x` because `xmin` was the only argument explicitly defined)

* Refresh README (#335)

* Refresh README

Closes #153
Closes #334

* remove README.Rmd

* Update README.md

* Classify vignettes on the website (#336)

Closes #178

* Make `.Rbuildignore` more comprehensive (#337)

* Make `.Rbuildignore` more comprehensive

Get rid of `NOTE` about unexpected top-level files

* Update .Rbuildignore

* Update to roxygen2 7.2.1 (#339)

* Format with latest version of styler (#341)

* Fixes #326 legend title use plot configuration for time profile plots (#343)

* Get rid of warnings and notes in R CMD check (#338)

* Fixes #333 set cap width of errorbars (#344)

* Fixes #333 set cap width of errorbars

Currently, width is a global setting applied the same way to all error bars

* Absolute cap values are now relative and width renamed to extent

Renaming width to extent to prevent user confusion when used for horizontal errorbars whose caps become vertical

* Fixes #333 cap extent renamed cap size and use consistent unit in pts

Co-authored-by: Indrajeet Patil <patilindrajeet.science@gmail.com>

* 303 obs map to shape (#351)

* Fixes #303 observed data map to shape

* Fixes #346 remove dynamic code

* Update documentation with latest roxygen

* format with styler

Co-authored-by: Indrajeet Patil <patilindrajeet.science@gmail.com>

* Fixes #353 time profile legend guide display and order shapes (#355)

* Fixes #356 display minor ticks (#357)

* Fixes #356 display minor ticks

* fix test

Co-authored-by: Indrajeet Patil <patilindrajeet.science@gmail.com>

* Fixes #354 ObservedDataMapping signature consistent with TimeProdfle (#358)

* Fixes #360 add linetype as internal splitting group for simulation range (#361)

* Fixes #350 default obs vs pred plot use same axes limits (#365)

The same option also centers residuals vs pred/time around 0

* format with {styler} (#366)

* Fixes #368 Add identity in Scaling enum (#371)

Also fix a typo in enum Shapes

* Fixes #375 Add spellcheck

* Fixes #362 introduce qq plots (#370)

* Fixes #362 introduce qq plots

* Remove empty y check overkill

Co-authored-by: Indrajeet Patil <patilindrajeet.science@gmail.com>

* Fixes #364 introduce cumulative time profile plots (#378)

* 374 enum listing molecules (#380)

* Fixes #375 enums listing all molecules, atoms and their configurations

* Fixes #379 Synchronize theme and molecule plots

* Rename Atoms and Molecules to  AtomPlots and MoleculePlots

* Fixes #381 Prevent log ticks from crashing plots (#382)

* Fixes #387 enforce factor type to prevent crash of colorBreaks (#388)

levels of character type variable is null possibly leading to null colorBreaks value

* Fixes #383 histogram can plot bars as frequency (#384)

* Fixes #383 histogram can plot bars as frequency

* Update documentation about default values of histogram

* Fixes #390 Fixes #391 observed and simulated time profiles (#393)

* Fixes #392 Create method for dual axis time profile plots (#396)

* Fixes #392 Create method for dual axis time profile plots

* Update test plot grid snapshot to latest

* Fixes #398 update documentation and website (#399)

* Fixes #398 update documentation and website

* Fixes #398 Update version and dev documentation

* Update release documentation

* Fixes #397 vignette code is run only if R version is >= 4.0 (#401)

* Increment AppVeyour version (1.4=>1.5) (#402)

Co-authored-by: Yuri05 <Yuri05@github.com>

* merge main into develop

---------

Co-authored-by: Michael Sevestre <michael@design2code.ca>
Co-authored-by: Pierre Chelle <45343665+pchelle@users.noreply.github.com>
Co-authored-by: Indrajeet Patil <patilindrajeet.science@gmail.com>
Co-authored-by: Pavel Balazki <pavel.balazki@gmail.com>
Co-authored-by: Yuri05 <Yuri05@github.com>
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.

get rid of warnings and notes in package check
4 participants