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

Continued work on practical R-Instat scripts for our library #9247

Open
rdstern opened this issue Nov 12, 2024 · 22 comments
Open

Continued work on practical R-Instat scripts for our library #9247

rdstern opened this issue Nov 12, 2024 · 22 comments
Assignees

Comments

@rdstern
Copy link
Collaborator

rdstern commented Nov 12, 2024

Our tutorials and other guides are usually in 2 forms.

  1. There is a video
  2. There is a practice guide

We are starting the process of getting a third form of these guides, namely as scripts. Here is tutorial 1 as a script;

Tutorial 1 r-script.zip

I like this new form to complement the two existing forms.

They should run block-by block easily and I suggest that is pretty quick and can add to our other tests of new versions. (It can't replace using the dialogs, because they might have changed from the saved script.)

I have also liked the role played by the Comments feature in each dialog. Usually it becomes a comment in the output and that should help, if we make the comments useful - i.e. don't always ignore it, so you get the default.

Now we find, similarly, it becomes a comment in the script, once you press To Script! Nice.

It is good to have well commented scripts in general. I suggest @rachelkg could improve on the comments in this draft, and work with @[email protected] to produce well commented scripts.

The scripts will also show weaknesses in our coding of the dialogs. I further suggest @beryl and @Rachel could query those weaknesses as issues, so the R-Instat code could be improved.

For example, in Tutorial 1 I suggest there is a better structure to the commands generated for the One Variable Summarise, compared to the One Variable Graph.

Then I suggest one of the developers could become the script "partner" working under @N-thony to get more consistency in the scripts for the different dialogs.

The example on graphs could be the first task. That can start any time, but is not to be merged for this week's update.

@berylwaswa
Copy link

Hello,
Below is the zipped file containing the r scripts for tutorial 1, tutorial 2 and the prepare menu practicals.

I have reviewed all three while testing R-Instat version .80 and they all worked fine.

R-Instat Scripts.zip

@berylwaswa
Copy link

Hello,
I have reviewed the computer skills needed for the R-Instat practical and created the r-script @rdstern. Please find it attached here.

computer_skills.zip

@derekagorhom
Copy link
Contributor

@berylwaswa and @rachelkg while running through the script for the computer_skills.zip. i found this error below
image
i think we need to solve this since the PC name varies from one user to another.
either we remove this or make some change if we still want this there.

@berylwaswa
Copy link

@derekagorhom I think it's best to change it based on where it will be saved?

@berylwaswa
Copy link

I have just created another r-script for the first Express start practical, please find it attached.
@derekagorhom I found no errors here, you can check it too.

Express start r-script.zip

@derekagorhom
Copy link
Contributor

@berylwaswa can you try

# Get the user's Documents directory
documents_path <- file.path(Sys.getenv("USERPROFILE"), "Documents")  # For Windows

# Save the R object as an RDS file with a proper name
saveRDS(object = data_book, file = file.path(documents_path, "computer_skills.RDS"))

let me know what you think about this

@berylwaswa
Copy link

@derekagorhom that worked fine there was no error throughout the script

@derekagorhom
Copy link
Contributor

derekagorhom commented Nov 19, 2024

@rdstern , @berylwaswa
After looking through the five scripts i was sent i am only able to clear Tutorial 1 r-script.
The other scripts should work fine if they are on beryl laptop or if the user has the latest verion;

a. This is not really a problem now but it might be, assuming the user has an older version or uses an upgraded version of R-instat. This line will generate an error for the user in both cases.
image

b. This second will give an error because these are not the user's file path on their PCs so for save RDS i created
image

# Get the user's Documents directory
documents_path <- file.path(Sys.getenv("USERPROFILE"), "Documents")  # For Windows

# Save the R object as an RDS file with a proper name
saveRDS(object = data_book, file = file.path(documents_path, "computer_skills.RDS"))

and for the export also i did

# Get the user's Documents directory
documents_path <- file.path(Sys.getenv("USERPROFILE"), "Documents")  # For Windows

# Define the file path for the Excel file
excel_file_path <- file.path(documents_path, "dodoma_by_year.xlsx")

# Export the data frame to an Excel file
rio::export(x = data_book$get_data_frame(data_name = "dodoma_by_year"), file = excel_file_path)

but the issue i have is they look more of a VB structure than an R structure for saving or exporting. Any advise on the two codes will be appreciated.

@rachelkg
Copy link
Contributor

rachelkg commented Nov 19, 2024

I also can run through tutorial 1 with no problem but I come to an error in tutorial 2 on the last command about saving the data. In the prepare script it is the export to excel and the save commands that get errors. This is consistent with your findings @derekagorhom. Who do you think might be able to help with your questions about this? I don't think anyone in this thread has enough coding experience. Maybe @N-thony? Do you have any thoughts on Derek's questions?

@N-thony
Copy link
Collaborator

N-thony commented Nov 20, 2024

@rdstern , @berylwaswa After looking through the five scripts i was sent i am only able to clear Tutorial 1 r-script. The other scripts should work fine if they are on beryl laptop or if the user has the latest verion;

a. This is not really a problem now but it might be, assuming the user has an older version or uses an upgraded version of R-instat. This line will generate an error for the user in both cases. image

Correct, this will give an error and not able to find the path when moving to a new version of R-Instat.
@berylwaswa @rachelkg @rdstern we can edit the code follow to dynamically get the file path.

# Current working directory
current_dir <- getwd()

# Construct the desired file path
file_path <- file.path(dirname(dirname(current_dir)), "Library", "Climatic", "climatic_guide_datasets.xlsx") 

# Importing the Dodoma Dataset into R-Instat

dodoma <- rio::import(file=file_path, guess_max=Inf, which=6)
data_book$import_data(data_tables=list(dodoma=dodoma))

b. This second will give an error because these are not the user's file path on their PCs so for save RDS i created image

# Get the user's Documents directory
documents_path <- file.path(Sys.getenv("USERPROFILE"), "Documents")  # For Windows

# Save the R object as an RDS file with a proper name
saveRDS(object = data_book, file = file.path(documents_path, "computer_skills.RDS"))

and for the export also i did

# Get the user's Documents directory
documents_path <- file.path(Sys.getenv("USERPROFILE"), "Documents")  # For Windows

# Define the file path for the Excel file
excel_file_path <- file.path(documents_path, "dodoma_by_year.xlsx")

# Export the data frame to an Excel file
rio::export(x = data_book$get_data_frame(data_name = "dodoma_by_year"), file = excel_file_path)

but the issue i have is they look more of a VB structure than an R structure for saving or exporting. Any advise on the two codes will be appreciated.

They are R code, and this looks good to me, we can pass directly the path in export or save code

# Saving the data for later use to an RDS file in the user's Documents directory

saveRDS(file=file.path(Sys.getenv("USERPROFILE"), "Documents", "computer_skills.RDS"), object=data_book)

or you can create a variable that will store the document path and re-use if the codes are all in the same file

documents_path <- file.path(Sys.getenv("USERPROFILE"), "Documents")

and for the exports we can have

# Export the data frame to an Excel file in the user's Documents directory
rio::export(
  x = data_book$get_data_frame(data_name = "dodoma_by_year"),
  file = file.path(Sys.getenv("USERPROFILE"), "Documents", "dodoma_by_year.xlsx")
)

@derekagorhom
Copy link
Contributor

@berylwaswa , @rachelkg
below is the updated code for R scripts to be put into R-instat, It contains all the previously sent files except the Prepare Menu practice r-script.R.
Can you kindly go through them and verify that they work well on your machines.
The updated code includes changes @N-thony suggested.
Kindly let me know how it goes.
Thanks

Updated R codes for the R-instat Scripts.zip

@berylwaswa
Copy link

@derekagorhom @N-thony

I have gone through the four scripts, 3 work fine; Tutorial 1, 2 and computer skills for R-Instat.

The express start script brings errors when I run it.

# Importing the Datasets in the Tutorial.RDS into R-Instat

data_book$import_RDS(data_RDS=new_RDS)
rm(new_RDS)

When I run the code above I get the error below
instat_CzkX6zj9ep

And when I run all the next lines that follow I get the error below;

instat_3NpMcqKNSy

The problems seems to be the data file cannot be found, I guess you have to edit something about the path again?

@N-thony
Copy link
Collaborator

N-thony commented Nov 20, 2024

@derekagorhom @N-thony

I have gone through the four scripts, 3 work fine; Tutorial 1, 2 and computer skills for R-Instat.

The express start script brings errors when I run it.

# Importing the Datasets in the Tutorial.RDS into R-Instat

data_book$import_RDS(data_RDS=new_RDS)
rm(new_RDS)

When I run the code above I get the error below instat_CzkX6zj9ep

And when I run all the next lines that follow I get the error below;

instat_3NpMcqKNSy

The problems seems to be the data file cannot be found, I guess you have to edit something about the path again?

@derekagorhom you have missed some code as you can see below. Have you tested this before asking @berylwaswa to test again?
image

@derekagorhom
Copy link
Contributor

@N-thony my mistake
i have given her another code to run and see if it works on her PC

@berylwaswa
Copy link

@derekagorhom here is another script you can check if it's okay, it works fine on my end.

fun with lists.zip

@berylwaswa
Copy link

berylwaswa commented Nov 25, 2024

@derekagorhom here is another script.

a tidy calculator r-script.zip

@berylwaswa
Copy link

@derekagorhom here is another r script to review.

fun with sequences.zip

@berylwaswa
Copy link

@derekagorhom here is another script, the last bit however may need editing please check it out.

a whole world of data.zip

@derekagorhom
Copy link
Contributor

derekagorhom commented Dec 4, 2024

@derekagorhom here is another script, the last bit however may need editing please check it out.

a whole world of data.zip

@berylwaswa this zip file seems to have two issues with the rcode
You can find them below:

# Producing a Scatter Plot in R-Instat

diamonds <- data_book$get_data_frame(data_name="diamonds")
last_graph <- ggplot2::ggplot(data=diamonds, mapping=ggplot2::aes(colour=cut, y=color, x=clarity)) + ggplot2::geom_jitter(width=0.40, height=0.40) + theme_grey()
data_book$add_object(data_name="diamonds", object_name="last_graph", object_type_label="graph", object_format="image", object=check_graph(graph_object=last_graph))
data_book$get_object_data(data_name="diamonds", object_name="last_graph", as_file=TRUE)
rm(list=c("last_graph", "diamonds"))


# Producing a Scatter Plot in R-Instat

diamonds <- data_book$get_data_frame(data_name="diamonds")
last_graph <- ggplot2::ggplot(data=diamonds, mapping=ggplot2::aes(colour=cut, x=clarity, y=color)) + ggplot2::geom_jitter(width=0.40, height=0.40) + theme_grey()
data_book$add_object(data_name="diamonds", object_name="last_graph", object_type_label="graph", object_format="image", object=check_graph(graph_object=last_graph))
data_book$get_object_data(data_name="diamonds", object_name="last_graph", as_file=TRUE)
rm(list=c("last_graph", "diamonds"))

kindly have a look at the code above, i do not see any difference between these 2 but they were both added and they produce the same results. Is there any reason why both r code were added to the script?

The second one is the last line in that script (see below)
image
I can guess you downloaded the file from MICS but it is currently not available in the R-Instat Data library.
Can you kindly send the RDS file so that i can be added to the library.
Thanks.

@berylwaswa
Copy link

@derekagorhom I have made the necessary changes; now below is the new script.

a whole world of data.zip

The MICS data file is bigger than 25mbs so I'm sharing it with you on drive.

Thanks.

@berylwaswa
Copy link

berylwaswa commented Dec 4, 2024 via email

@berylwaswa
Copy link

@derekagorhom here is another script. It works fine in the developer's version, but there is an error in the 0.8.0 version when plotting a multiple-line plot.

line plots.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants