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

write_project function kills R #145

Closed
ricschuster opened this issue Aug 18, 2021 · 18 comments
Closed

write_project function kills R #145

ricschuster opened this issue Aug 18, 2021 · 18 comments
Labels
bug Something isn't working

Comments

@ricschuster
Copy link
Contributor

Hi Jeff,

I've just modified your Ontario pilot data script and got all the way to the write_project part:

## save project to disk
write_project(
  x = append(themes, append(includes, weights)),
  dataset = dataset,
  name = "Quebec pilot dataset",
  path =
    "out/quebec_pilot/quebec_pilot.yaml",
  spatial_path =
    "out/quebec_pilot/quebec_pilot_spatial.tif",
  attribute_path =
    "out/quebec_pilot/quebec_pilot_attribute.csv.gz",
  boundary_path =
    "out/quebec_pilot/quebec_pilot_boundary.csv.gz",
  mode = "advanced"
)

When I go ahead and run this code my R session quits. No warning or anything, it just closes. Do you have ideas how to trouble shoot this?

@jeffreyhanson
Copy link
Contributor

Hmm, that's weird. Can you send me the script and I'll take a look at it?

@jeffreyhanson jeffreyhanson added the bug Something isn't working label Aug 18, 2021
@ricschuster
Copy link
Contributor Author

Data and script are here: https://github.com/ricschuster/Tool1_pilot_QC
prep_Tool1_update.R
Thanks Jeff!

@jeffreyhanson
Copy link
Contributor

When you run the code, do any of the files get created in the output folder or only some of them?

@jeffreyhanson
Copy link
Contributor

I noticed that some of the theme/feature/include/weights names had accents - I wonder if this could be causing issues?

@ricschuster
Copy link
Contributor Author

When you run the code, do any of the files get created in the output folder or only some of them?

None of them.

@ricschuster
Copy link
Contributor Author

I noticed that some of the theme/feature/include/weights names had accents - I wonder if this could be causing issues?

That could be it. Will try changing them tomorrow.

@jeffreyhanson
Copy link
Contributor

jeffreyhanson commented Aug 18, 2021

Ok - this suggests that it might be code writing the YAML file that is failing (since this is the first file that should be written).

What happens if you try running the following code (after running everything except write_project(...) in the script)?

# rename variables based on write_project parameters
x = append(themes, append(includes, weights)),
dataset = dataset,
name = "Quebec pilot dataset",
path =
  "out/quebec_pilot/quebec_pilot.yaml",
spatial_path =
  "out/quebec_pilot/quebec_pilot_spatial.tif",
attribute_path =
  "out/quebec_pilot/quebec_pilot_attribute.csv.gz",
boundary_path =
  "out/quebec_pilot/quebec_pilot_boundary.csv.gz",
mode = "advanced"

# code copied from write_project
## create setting list for themes
themes_idx <- vapply(x, inherits, what = "Theme", logical(1))
themes_params <- lapply(x[themes_idx], function(x) x$export())

## create setting list for weights
weights_idx <- vapply(x, inherits, what = "Weight", logical(1))
weights_params <- lapply(x[weights_idx], function(x) x$export())

## create setting list for includes
includes_idx <- vapply(x, inherits, what = "Include", logical(1))
includes_params <- lapply(x[includes_idx], function(x) x$export())

## create full settings list
params <- list(
  name = name,
  spatial_path = basename(spatial_path),
  attribute_path = basename(attribute_path),
  boundary_path = basename(boundary_path),
  mode = mode,
  themes = themes_params,
  weights = weights_params,
  includes = includes_params
)

## save configuration file to disk
yaml::write_yaml(params, path)

@ricschuster
Copy link
Contributor Author

R still crashes without throwing an error.
I've also tried the accents and unless I've missed some, the problem persists.

@ricschuster
Copy link
Contributor Author

It was the . in some of the variable names that messed things up. I've replaced them with and it works now.

@ricschuster
Copy link
Contributor Author

I did push the project to the server, but now get this error:

image

Do you have a way to test projects setup, so I can figure out what went wrong?

@jeffreyhanson
Copy link
Contributor

Yeah, if you clone the repo, and then use make debug, then it will launch the app locally. Now it will print stuff to the console when you get an error. You can import the project manually to test it (i.e. manually uploding project files). Does that help?

@jeffreyhanson
Copy link
Contributor

Or, just copy in the project files into ./inst/extdata/projects temporarily to debug it (but don't push these files to GitHub unless you want them included as a built-in demo dataset).

@jeffreyhanson
Copy link
Contributor

It was the . in some of the variable names that messed things up. I've replaced them with and it works now.

To avoid this in the future, I'll update the code so that you can't create variable with a . its name (i.e. it will throw an error).

@ricschuster
Copy link
Contributor Author

Thanks!

@jeffreyhanson
Copy link
Contributor

Ah - just to be clear do you mean the "index" for a varible? I just checked and variables don't have "name" (strictly speaking).

@jeffreyhanson
Copy link
Contributor

jeffreyhanson commented Aug 19, 2021

It's the theme/include/weight name specifically.

@ricschuster
Copy link
Contributor Author

I've finally got the pilot data to work on the server.
The yaml issue, we've already addressed/talked about.

The rest was related to the special characters in French. I had to convert them all to 'normal' characters for this to work. I did it for both the layer names and the variable names. Not sure why this is an issue.

@jeffreyhanson
Copy link
Contributor

It seems that the encoding issue is related to the yaml R package (see vubiostat/r-yaml#90). To address this, I'll try wrapping the names in enc2utf8(...) before writing them to disk.

jeffreyhanson added a commit that referenced this issue Aug 23, 2021
this is needed since dots are no longer allowed in names per #145
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants