Completely new to R (being introduced to it in a class right now).
I'm having some issues just getting my data to read in. I'm sourcing it from a webpage: (ftp://webftp.vancouver.ca/opendata/csv/crime_2004.csv) and putting both the URL and the file path if I download the .csv file is giving me the following error message:
"Error in open.connection(file, "rt") :
URL using bad/illegal format or missing URL"
My code:
fname = curl("/Users/shane_1001/Downloads/crime_2004.csv")
data = read.csv(fname, header=T)
print(head(data))
Related
I am new to openTBS,
I tried the html and php code from 'https://www.tinybutstrong.com/opentbs.php?demo' and 'https://www.tinybutstrong.com/plugins/opentbs/demo/demo_merge.php', and I can't manage to get the "$TBS->Show(OPENTBS_DOWNLOAD)" command working :
I get a page with chinese characters and no file is being downloaded.
Sample of the page :
PK鸙_S^�2''mimetypeapplication/vnd.oasis.opendocument.textPK鸙_SConfigurations2/popupmenu/PK鸙_SConfigurations2/floater/PK鸙_S'Configurations2/accelerator/current.xmlPKPK鸙_SConfigurations2/images/Bitmaps/PK鸙_SConfigurations2/menubar/PK鸙_SConfigurations2/progressbar/PK鸙_SConfigurations2/statusbar
The $TBS->Show(OPENTBS_FILE) command is working and a merged odt file is saved.
Any help would be appreciated.
Am trying to read a .docx file which is inside my project folder via PHP Word library. I have included autoloader like this :
include_once 'vendor/autoload.php'; in my controller.
CODE FOR FUNCTION IN CONTROLLER:
function test_phpword()
{
$a=base_url();
$path=$a."".'123.docx';
$source =$path;
echo date('H:i:s'), " Reading contents from `{$source}`";
$phpWord = \PhpOffice\PhpWord\IOFactory::load($source);
echo write($phpWord, basename(__FILE__, '.php'), $writers);
}
BUT GETTING ERROR LIKE BELOW:
06:18:42 Reading contents from http://localhost/myproject/123.docx
Fatal error: Uncaught Exception: Cannot find archive file. in /opt/lampp/htdocs/myproject/vendor/phpoffice/common/src/Common/XMLReader.php:51
Try this
Change
$path=$a."".'123.docx';
to
$path='123.docx';
And put 123.docx beside your php script file. make sure the two files are in the same place. Run your php script again.
If this helps and works fine you can check the file path and make proper change to your php program.
While loading the path, you have to give relative path to the doc file as shown below,
$random_name = 123.docx;
$contents = \PhpOffice\PhpWord\IOFactory::load('../uploads/'.$random_name);
I don't know whats your $base_url, but it will not work if it is absolute path like http://path/to/doc/file.
I have worked on it and tested. Hope it helps.
I am using the Watson document conversion service. I have a set of .html files that I want to pass into the Watson API. I created two lists the first one (File_Name_List) contains the names of the .html files and the second (File_Name_List_TXT) contains the names of the .txt files I want the output of the Watson service to write to. Everytime I run the code below it gives me the following error: ValueError: I/O operation on closed file. I cannot figure out what the issue is - any help would be appreciated.
for file in File_Name_List:
for file_txt in File_Name_List_TXT:
f = open(file_txt,'w')
with open(join(dirname(__file__), file), 'r') as document: config = {'conversion_target': DocumentConversionV1.NORMALIZED_TEXT}
f.write(str(document_conversion.convert_document(document=document, config=config, media_type='text/plain').content).lower())
f.close()
Command Prompt its not working since i am using a generic path to open a excel file. Here is the error message:
T:\PointOfSale\Projects\Automated Testing\TASWeb\TP\TP_Branch>ruby -rubygems Tes
tTP_UK.rb
TestTP_UK.rb:19:in 'method_missing': (in OLE method `Open': )(WIN32OLERuntimeEr
ror)
OLE error code:800A03EC in Microsoft Excel
'./../../../MasterFile.xls' could not be found. Check the spelling of the
file name, and verify that the file location is correct.
If you are trying to open the file from your list of most recently used files, m
ake sure that the file has not been renamed, moved, or deleted.
HRESULT error code:0x80020009
Exception occurred.
from TestTP_UK.rb:19:in `'
enter code here'
Generic path code
excel = WIN32OLE::new("excel.Application")
path = "#{File.dirname(__FILE__)}/../../../MasterFile.xls"
workbook = excel.Workbooks.Open(path)
worksheet = workbook.WorkSheets(1) # Get first workbook
site = worksheet.Range('A2').Value # Get the value at cell in worksheet.
workbook.Close
excel.Quit
Any Ideas
I believe you need to use an absolute path rather than a relative path when opening the file:
path = File.expand_path("../../../../MasterFile.xls", __FILE__)
Note that you will also need an additional '..' when using expand_path, since the first '..' is going back from the file.
I am working on writing a ruby script to iterate through a file containing a list of file paths to open in Microsoft Excel. I read the file like this:
file_names = IO.readlines('D:\TEST_1\file_names.txt')
Next, I create an array of file names from each line of the parsed file (thus containing an array of file paths). Finally, I loop through that array with the following code, to open the documents:
require 'win32ole'
xl = WIN32OLE.new('Excel.Application')
xl.Visible = 1
file_names.each do |file_name|
wb1=xl.Workbooks.Open(file_name)
ws1=wb1.worksheets(1)
end
That first call to parse file_names.txt produces this exception, which I am having difficulty understanding:
Test4.rb:6:in 'method_missing'
OLE error code:800A03EC in Microsoft Office
Excel 'D:\Test_1\1.xlsx' couldnot be found. Check the spelling of
the file name, and verify that the file location is correct.
if you are trying to open the file from your list most recently used
files, make sure that the file has not been renamed, moved or deleted
HR Error code : 0x80020009 Exception occurred. from Test4.rb:6:in
'block in ' from Test4.rb:5:in 'each' from Test4.rb:5:in
''
This error does not appear when I pass a single file name (instead of a file path) as my parameter - so why do I get it here? Any help would be much appreciated.
At first look you are not using the variable "file_name" but a symbol :file_name.
file_array.each do |file_name|
wb1=xl.Workbooks.Open(file_name)
ws1=wb1.worksheets(1)
end