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

locator returns incorrect coordinates #12682

Open
4 tasks done
rhijmans opened this issue Feb 9, 2023 · 9 comments
Open
4 tasks done

locator returns incorrect coordinates #12682

rhijmans opened this issue Feb 9, 2023 · 9 comments
Labels
bug info needed Additional information requested—reprex, steps, open question, etc. plots

Comments

@rhijmans
Copy link

rhijmans commented Feb 9, 2023

System details

RStudio Edition : Desktop
RStudio Version : 2022.12.0 Build 353
OS Version      :  Windows
R Version       : R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19043)

Steps to reproduce the problem

plot(c(-1, 1, 1, -1, 0), c(-1, -1, 1, 1, 0))
xy = locator(1)
# click on x=0, y=0
xy
#$x
#[1] -0.450672
#
#$y
#[1] 0.5113197

Description

locator does not return the correct coordinates in the default R-Studio canvas. This has been reported here before: #8571 and elsewhere. But the issues went stale without resolution or work-around for the default device.

This used to work in the past on some version of R-studio, or under some conditions.

locator works if you first use dev.new("x11") works but that is tricky and cannot be used in a function that calls locator (it is too late by then). For example, this breaks terra::click and terra::draw in R-Studio.

  • I have read the guide for submitting good bug reports.
  • I have installed the latest version of RStudio, and confirmed that the issue still persists.
  • If I am reporting an RStudio crash, I have included a diagnostics report.
  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
@rhijmans rhijmans added bug new New incoming issues, ready for initial review. labels Feb 9, 2023
@ronblum ronblum added plots and removed new New incoming issues, ready for initial review. labels Feb 9, 2023
@LuisLauM
Copy link

This is weird, my system has almost the same configuration than yours, but it works well:

RStudio Edition : Desktop
RStudio Version : 2022.12.0 Build 353
OS Version      : Windows
R Version       : R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)
plot(c(-1, 1, 1, -1, 0), c(-1, -1, 1, 1, 0))
xy = locator(1)
# click on x=0, y=0
xy
#$x (in my PC)
#[1] -0.0009412585
#
#$y (in my PC)
#[1] 0.003767004

I have tried changing the size of the plot panel inside RStudio, but the results are still quite well.

@ronakv10
Copy link

If you're having issue with locator function then it might be because of the zoom level of the Rstudio or Scale of the windows (Display settings). Change both the zoom levels to 100% as shown:

Changing the zoom level of RStudio

Go to Tools -> Global Options -> Appearance -> Zoom (change that to 100%)

photo_2

Changing the Scale of Windows Display

This happens often in the laptops where the Scale is 150% by default. You have to change that 100%.

Right click on windows' desktop, Display Setting -> Scale (change that to 100%)

photo_

@ronblum
Copy link
Contributor

ronblum commented Mar 30, 2023

@rhijmans A couple of things:

  1. Have you tried @ronakv10's workaround? I'm curious if that worked.
  2. What happens if you do the same but in R outside of RStudio?

@ronblum ronblum added the info needed Additional information requested—reprex, steps, open question, etc. label Mar 30, 2023
@rhijmans
Copy link
Author

rhijmans commented Apr 5, 2023

  1. The locator indeed works if I set the "System/Display/Scale and Layout" setting to 100%. That is not a viable setting in my case, as it makes the font too small to read. I use 150%.

  2. I do not see this problem in command-line R or RGui (irrespective of the Scale and Layout setting).

@soumyaray
Copy link

soumyaray commented Apr 16, 2023

Setting the scaling on Windows to 100% seems to help some of my package's users, but not completely. RStudio's own zoom setting also contributes. But setting both to 100% does not seem to resolve it for everyone: users are reporting that Windows scaling of 100% and RStudio zoom to 70%-80% produces best results.

A larger issue for me is that the behavior is also broken for users on posit.cloud (even on my Mac, where it works on native RStudio). There is no scaling option for RStudio on the cloud platform.

@yufree
Copy link

yufree commented May 20, 2023

Same here. I am using RStudio server and there are no 'zoom' option in the 'Appearance'. When I used locator, the coordinates will shift a lot.

@segawat
Copy link

segawat commented Oct 11, 2023

Even setting in RStudio the Zoom Scale to 100%, as suggested by @ronakv10, the locator function produces incorrect positions in RStudio. The exact values depend on the size of the window.

As reported by @rhijmans, the bug does not exist in R alone (RGui).

As a workaround, we are currently opening an external graphic window, where the locator function is working perfectly:

  1. graphics.off()
  2. windows() (for Windows) / quartz() (for Mac) / x11() (for UNIX)

The fixing of this bug by an upcoming RStudio version would be highly appreciated.

@soumyaray
Copy link

@segawat can I ask which method you are using to reliably determine the OS to know which of windows(), quartz() and x11() to call? Would it just be version$os and parsing the initial part of the name (linux/darwin/etc.)? An unfortunate workaround but its best I get around to doing this too.

@segawat
Copy link

segawat commented Dec 7, 2023

@soumyaray I am not sure, if I can properly help you, but a system-independent way of opening an external graphic window from RStudio could be:

  1. graphics.off()
  2. dev.new(noRStudioGD = TRUE)

Please also check the following discussion on Stack Overflow and maybe the entry on x11() in the R Documentation .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug info needed Additional information requested—reprex, steps, open question, etc. plots
Projects
None yet
Development

No branches or pull requests

7 participants