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

lexical error: invalid char in json text #11

Closed
superboreen opened this issue Jan 6, 2022 · 19 comments · Fixed by #16
Closed

lexical error: invalid char in json text #11

superboreen opened this issue Jan 6, 2022 · 19 comments · Fixed by #16

Comments

@superboreen
Copy link

When I run the example I get this error. Any advice appreciated.

Error: lexical error: invalid char in json text.
~/.config/RStudio/rstudio-prefs
(right here) ------^

Am on Ubuntu 20.04.3 LTS, RStudio 2021.09.0 Build 351, R version 4.1.2 (2021-11-01)

@ddsjoberg
Copy link
Owner

Thanks for the post @superboreen .

Can you run the code again and give the trace of the error, so i can see exactly where it occurs.

@superboreen
Copy link
Author

Not sure how I do that. Can you advise.

@superboreen
Copy link
Author

Actually I realise the error I posted above is a bit misleading. When I get the error in the RStudio console, the (right here) ------^ arrow is actually pointing at the forward slash. Maybe it is a path thing?

@ddsjoberg
Copy link
Owner

here's a chapter on debugging including tracebacks
https://rstats.wtf/debugging-r-code.html

@superboreen
Copy link
Author

Ok thanks, I will study that when I have a little time. FWIW for now, I manged to fumble into debug somehow and it would appears that it is the following line that is throwing the error:

list_current_prefs <- jsonlite::fromJSON(rstudio_config_path("rstudio-prefs.json"))

@ddsjoberg
Copy link
Owner

can you confirm that the path exists rstudio_config_path("rstudio-prefs.json")? if it does, what does that file look like?

@superboreen
Copy link
Author

It does.
Looks like this:

{
"posix_terminal_shell": "bash",
"save_workspace": "never",
"load_workspace": false,
"initial_working_directory": "/MEGAsync/MEGAcave/code0",
"restore_last_project": false,
"panes": {
"quadrants": [
"Source",
"Console",
"TabSet2",
"TabSet1"
],
"tabSet1": [
"Environment",
"History",
"Connections",
"Build",
"VCS",
"Tutorial",
"Presentation"
],
"tabSet2": [
"Files",
"Plots",
"Packages",
"Help",
"Viewer"
],
"hiddenTabSet": [],
"console_left_on_top": false,
"console_right_on_top": true,
"additional_source_columns": 1
},
"jobs_tab_visibility": "shown",
"default_project_location": "
/MEGAsync/MEGAcave/code0",
"python_type": "system",
"python_version": "3.8.10",
"python_path": "/usr/bin/python3",
"margin_column": 76,
"highlight_r_function_calls": true,
"rainbow_parentheses": true,
"rmd_chunk_output_inline": false,
"rmd_viewer_type": "pane",
"latex_preview_on_cursor_idle": "inline_only",
"document_author": "Superboreen",
"show_panel_focus_rectangle": true,
"check_arguments_to_r_function_calls": true,
"check_unexpected_assignment_in_function_call": true,
"warn_if_no_such_variable_in_scope": true,
"warn_variable_defined_but_not_used": true,
"style_diagnostics": true,
"show_indent_guides": true,
"rmd_preferred_template_path": "/home/user1/R/x86_64-pc-linux-gnu-library/4.0/skimr/rmarkdown/templates/fonts-in-skimr",
"soft_wrap_r_files": true,
"continue_comments_on_newline": true,
"spelling_dictionary_language": "en_GB",
"editor_theme": "Green",
"font_size_points": 12,
"highlight_selected_line": true,
"source_with_echo": true
}

@ddsjoberg
Copy link
Owner

Why is some text present with strike through? This is meant to be a plain text file

@superboreen
Copy link
Author

Don't know. Github did that when I pasted. No strikethrough in the original.

@ddsjoberg
Copy link
Owner

thanks for the clarification.

if you try to read this JSON file on your machine (outside of the package), do you still get the error?

@superboreen
Copy link
Author

superboreen commented Jan 7, 2022

Not if I use the lower case filename. See below.

> result <- fromJSON(file = "~/.config/rstudio/rstudio-prefs.json")
> file.exists("~/.config/rstudio/rstudio-prefs.json")
[1] TRUE
> result <- fromJSON(file = "~/.config/rstudio/RStudio-prefs.json")
Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") :
  cannot open file '/home/user1/.config/rstudio/RStudio-prefs.json': No such file or directory
> file.exists("~/.config/rstudio/RStudio-prefs.json")
[1] FALSE

@ddsjoberg
Copy link
Owner

Thank you again @superboreen for reporting the issue. I'm not a Linux user and I think it's due to the case sensitivity of the Linux file system. Can you please report here how the following files appear on your machine (with correct capitalization), and I'll update the files specifications in the package.

~/.config/rstudio/rstudio-prefs.json
~/.config/rstudio/keybindings/addins.json
~/.config/rstudio/keybindings/editor_bindings.json
~/.config/rstudio/keybindings/rstudio_bindings.json

@superboreen
Copy link
Author

They are all lowercase as you show above

addins.json
editor_bindings.json
rstudio_bindings.json
rstudio-prefs.json

@ddsjoberg
Copy link
Owner

hey hey @superboreen !

I wanted to update you....I don't have a linux machine to test on, unfortunately, and I also don't have time to continue debugging.

I am planning an update that should bypass this issue in the next couple of months FYI. Sorry I can't solve it immediately

@superboreen
Copy link
Author

No problem. Thanks for the update. I will keep an eye out for developments. Best of luck.

@jetroant
Copy link

jetroant commented May 7, 2022

Hi, just to let you know, I had the same issue on my Linux machine and it was caused by the fact that rstudio_config_path() returns ~/.config/RStudio, while at least on my machine the rstudio-prefs.json file lives in ~/.config/rstudio. For me then simply setting

base <- rappdirs::user_config_dir("rstudio", os = "unix")

in rstudio_config_path() solved the problem. Might not be a general solution though, as I suppose with some unix machines the json-file still lives in ~/.config/RStudio after all.

@ddsjoberg
Copy link
Owner

Thank you @jetroant and @superboreen for the reports!

FYI, I wrote this for my team and we're all on Windows. I don't have the bandwidth at the moment or access to a Linux machine to make updates. Happy to review a Pull Request if you have a chance to create one though.

@ddsjoberg
Copy link
Owner

@superboreen @jetroant I've finally gotten around to making this change. The update is in this pull request branch (#16). If you have a chance, it would be fantastic, if you can let me know if your issues are resolved.

@ddsjoberg
Copy link
Owner

UDPATE: @jetroant @superboreen the pull request has been merged, and is now in the main branch of the repo. But please do take a look when you have a moment and let me know.

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 a pull request may close this issue.

3 participants