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

Windows is severely mistreated by jaspTools::analysisOptions #27

Open
JorisGoosen opened this issue Feb 18, 2022 · 2 comments
Open

Windows is severely mistreated by jaspTools::analysisOptions #27

JorisGoosen opened this issue Feb 18, 2022 · 2 comments
Assignees

Comments

@JorisGoosen
Copy link
Contributor

JorisGoosen commented Feb 18, 2022

While helping someone out I ran into this code:

if (grepl("[{}\":]", source)) { # json string

Which works fine on unix to discriminate filenames from json as is evidenced by:

} else if (file.exists(source)) { # .jasp file

But on Windows this leads into inevitable problems with things like C:\bla\bla.

So I suggest changing the order, first check if the "file" exists and if not treat it as possible json.
What do you think @vandenman @Kucharssim

My workaround for this problem is: jaspTools:::analysisOptionsFromJASPfile(...)

@JorisGoosen JorisGoosen self-assigned this Feb 18, 2022
@Kucharssim
Copy link
Member

Ah, this is annoying!

So I suggest changing the order, first check if the "file" exists and if not treat it as possible json.

Yeah that should work right? Another solution could be to introduce different arguments for each type so that people can call the function like analysisOptions(path = "C:\path\to\file.jasp"), analysisOptions(json = "[1,2,3]"), analysisOptions(analysis="Descriptives") or something like that. Not sure whether it's worth the hassle though.

@vandenman
Copy link
Contributor

So I suggest changing the order, first check if the "file" exists and if not treat it as possible json.

Sounds reasonable to me.

In addition, it might be a good idea to use jsonlite::validate to check if something is actually json. For example

res <- jsonlite::validate(r"(
  {
    "key": "C:\bla\bla
  }
)")

res
#> [1] FALSE
#> attr(,"offset")
#> [1] 27
#> attr(,"err")
#> [1] "lexical error: invalid character inside string.\n                {     \"key\": \"C:\\bla\\bla   } \n                     (right here) ------^\n"
cat(attr(res, "err"))
#> lexical error: invalid character inside string.
#>                 {     "key": "C:\bla\bla   } 
#>                      (right here) ------^

could be used as an addition to

jaspTools/R/options.R

Lines 62 to 65 in 9895359

if (!grepl("^\\{.*\\}$", source))
stop("Your json is invalid, please copy the entire message
including the outer braces { } that was send to R in the Qt terminal.
Remember to use single quotes around the message.")

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

No branches or pull requests

3 participants